We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2177

Summary: SDL_GetSystemRAM() always returns 0 on Windows 8.1
Product: SDL Reporter: Justin Skiles <justin.d.skiles>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2    
Version: HG 2.1   
Hardware: x86_64   
OS: Windows 8   
Attachments: DxDiag of my computer.

Description Justin Skiles 2013-10-23 22:42:23 UTC
Created attachment 1395 [details]
DxDiag of my computer.

I tried using the new SDL_GetSystemRAM() function, but it always returns 0 on my machine, described by the DxDiag file attached.

However, I have determined the cause.

In SDL_cpuinfo.c:

            MEMORYSTATUSEX stat;
            if (GlobalMemoryStatusEx(&stat)) {
                SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
            }

Should actually be:
            MEMORYSTATUSEX stat;
            stat.dwLength = sizeof(stat);
            if (GlobalMemoryStatusEx(&stat)) {
                SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
            }

Notice the subtle difference is that we must initialize "dwLength" with the size of the struct. This is documented here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366770%28v=vs.85%29.aspx

----
dwLength
The size of the structure, in bytes. You must set this member before calling GlobalMemoryStatusEx.
----
Comment 1 Justin Skiles 2013-10-23 22:53:05 UTC
I should have noted that after making the change, the function returned "8085" (MB) as expected. That translates to the approximate 8 GB of RAM that I had available.
Comment 2 Ryan C. Gordon 2013-10-23 23:53:00 UTC
This patch is now https://hg.libsdl.org/SDL/rev/9ec71e56071c ... thanks!

--ryan.