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 - SDL_GetSystemRAM() always returns 0 on Windows 8.1
Summary: SDL_GetSystemRAM() always returns 0 on Windows 8.1
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.1
Hardware: x86_64 Windows 8
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-23 22:42 UTC by Justin Skiles
Modified: 2013-10-23 23:53 UTC (History)
0 users

See Also:


Attachments
DxDiag of my computer. (897 bytes, text/plain)
2013-10-23 22:42 UTC, Justin Skiles
Details

Note You need to log in before you can comment on or make changes to this bug.
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.