Found the cause of the MSVC release SDL.dll crash

Ok, after some severe reverse-engineering I found the cause of the crash
I get in the release version of the MSVC compiled SDL.dll. The problem
lies in a calling convention mixup: The three wglXXX() functions are
__stdcall (or WINAPI) NOT __cdecl as declared in the SDL library. Each
time one of these function is called in SDL the arguments on the stack
are removed twice … this can’t run clean =)

The following code fixed the problem for me:

In the file <src/video/wincommon/SDL_wingl_c.h> modify:
HGLRC (*wglCreateContext)(HDC hdc);
BOOL (*wglDeleteContext)(HGLRC hglrc);
BOOL (*wglMakeCurrent)(HDC hdc, HGLRC hglrc);
to this:
HGLRC (WINAPI *wglCreateContext)(HDC hdc);
BOOL (WINAPI *wglDeleteContext)(HGLRC hglrc);
BOOL (WINAPI *wglMakeCurrent)(HDC hdc, HGLRC hglrc);

In the file <src/video/wincommon/SDL_wingl.c> modify:
this->gl_data->wglCreateContext = (HGLRC ()(HDC))
GetProcAddress(handle, “wglCreateContext”);
this->gl_data->wglDeleteContext = (BOOL (
)(HGLRC))
GetProcAddress(handle, “wglDeleteContext”);
this->gl_data->wglMakeCurrent = (BOOL (*)(HDC, HGLRC))
GetProcAddress(handle, “wglMakeCurrent”);
to this:
this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC))
GetProcAddress(handle, “wglCreateContext”);
this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
GetProcAddress(handle, “wglDeleteContext”);
this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
GetProcAddress(handle, “wglMakeCurrent”);

There is still a problem when I quit my application, it crash on a wierd
address. Well, I will try to fix this too.

I hope the above fix will give the dev-team enough hints to fix the
problem :wink:
+Beosil

Ok, after some severe reverse-engineering I found the cause of the crash
I get in the release version of the MSVC compiled SDL.dll. The problem
lies in a calling convention mixup: The three wglXXX() functions are
__stdcall (or WINAPI) NOT __cdecl as declared in the SDL library. Each
time one of these function is called in SDL the arguments on the stack
are removed twice … this can’t run clean =)

Wow, thank you very much.
The fix will go into CVS very soon.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec