Hi Dee, all,

On 13/12/2011 11:36, Diederick C. Niehorster wrote:
I didn't see any errors in the debugger output. Also no problem with a
release build with everything unchanged from their defaults.

Interesting. I have found the same problem whether I use VS 2008, 2010, or MinGW, release or debug build. It only happens in 2.8.0, not 2.6.0.

I've done some more digging, and I found the access violation happens when fgCloseWindow() is called *after* the CRT exit() function has been called. It happens on the call wglMakeCurrent(NULL, NULL) on line 1540 of "freeglut_window.c", but any OpenGL call seems to cause an access violation at this point. The call stack is as follows:
freeglut.dll!fgCloseWindow(tagSFG_Window * window=0x00171d88)  Line 1539
freeglut.dll!fgDestroyWindow(tagSFG_Window * window=0x00171d88)  Line 224 + 0x9 bytes
freeglut.dll!fgDestroyStructure()  Line 377 + 0xb bytes
freeglut.dll!fgDeinitialize()  Line 424
freeglut.dll!_CRT_INIT(void * hDllHandle=0x72120000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 449
freeglut.dll!__DllMainCRTStartup(void * hDllHandle=0x72120000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 560 + 0x11 bytes
freeglut.dll!_DllMainCRTStartup(void * hDllHandle=0x72120000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 510 + 0x11 bytes
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
msvcr90d.dll!__crtExitProcess(int status=0)  Line 732
msvcr90d.dll!doexit(int code=0, int quick=0, int retcaller=0)  Line 644 + 0x9 bytes
msvcr90d.dll!exit(int code=0)  Line 412 + 0xd bytes
I think the problem is that we are making calls to the OpenGL library after it has been unloaded from the process' virtual address space. Comparing 2.8.0 with 2.6.0 I see that we have added a "atexit(fgDeinitialize)" on line 393 of "freeglut_init.c" (revision 897). Commenting the atexit() out results in the application exiting cleanly, and explains why the issue happens only in 2.8.0. I don't have a proposed fix as I don't know what exactly needs to be cleaned up at this point, and what the consequences of not cleaning it up would be.