SwapBuffers crashes my program!

I have an OpenGL program that works on all but one of my computers. This is a desktop with Vista 64 and Radeon HD4850. The problem seems to be in my call to SwapBuffers (hdc).

It compiles fine and then gives me an exception:

Unhandled exception at 0x00000000 in Program.exe: 0xC0000005: Access violation.

Using VC ++ to break before calling SwapBuffers shows the value of hdc:

0xfe011734 {unused = ???} CXX0030: Error: expression could not be evaluated

Does anyone know what could happen? Is there anything about SwapBuffers that changes from one PC to another? I got it to work on XP32, XP64 and (other) Vista64.

while (!quit) { if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) { if (msg.message == WM_QUIT) quit = true; TranslateMessage(&msg); DispatchMessage(&msg); } renderFrame(); //draws the scene SwapBuffers(hdc); if (GetAsyncKeyState(VK_ESCAPE)) shutdown(); think(); //calculates object positions, etc. } 

Problem System Drivers (HD4850) updated. I ran and wrote the program on another Vista64 system with Radeon HD4870, also with modern drivers. As far as I know, the drivers for these two cards are almost identical, as in the HD48xx series. For this reason, it seems strange that the GPU is causing the problem.

Anyway, am I mistaken or is it a memory problem? (Access Violation)

In addition, if I delete the SwapBuffers (hdc) call, the program seems to work fine, although it doesn’t work, of course, because framebuffers never change places. But it is at least stable.

Call Stack (-> - ptr stack):

  ATKOGL32.dll!6aef27bc() opengl32.dll!665edb2d() opengl32.dll!665f80d1() gdi32.dll!75e14104() -> MyProg.exe!WinMain(HINSTANCE__ * hinstance=0x009a0000, HINSTANCE__ * hprevinstance=0x00000000, char * lpcmdline=0x003b4a51, int nshowcmd=1) Line 259 + 0xe bytes MyProg.exe!__tmainCRTStartup() Line 578 + 0x35 bytes MyProg.exe!WinMainCRTStartup() Line 400 kernel32.dll!7641e3f3() ntdll.dll!777dcfed() ntdll.dll!777dd1ff() 

Here is the assembly (-> the following instruction must be executed):

  SwapBuffers(hdc); 009B1B5C mov esi,esp 009B1B5E mov eax,dword ptr [hdc (9BF874h)] 009B1B63 push eax 009B1B64 call dword ptr [ __imp__SwapBuffers@4 (0E1040Ch)] -> 009B1B6A cmp esi,esp 009B1B6C call @ILT+780(__RTC_CheckEsp) (9B1311h) 
+4
source share
3 answers

This is almost certainly a bug in the drivers. The reason you cannot see the hdc value is because the top stack frame for the crash is actually inside ATKOGL32.dll, but since there are no characters for this, the debugger shows you its code. As far as I can tell, ATKOGL32.dll is actually an ASUS wrapper for the ATI driver and where the crash occurs. You might want to install the spare ATI drivers from amd.com and see if the error persists.

While a driver should never crash no matter what series of OpenGL calls you make, my experience usually crashes as a result of some invalid call that your program makes. Technically, this should simply be ignored and the error state set, but this is not always what happens. You can easily check for any invalid OpenGL calls with a program like gDebugger.

0
source

It looks like you could access the HDC after the window was destroyed, will the problem go away if you exit the loop as soon as you get WM_QUIT?

+1
source

Whatever hdc is installed, it does not look right. Is a window created before this call? Is there any threading associated with this application that can damage hdc?

Try creating a watch at the address of hdc itself and see when the value changes to an invalid location, which may give you a hint about where it changes.

0
source

All Articles