wglDeleteContext exception error

Started by
12 comments, last by Damocles 19 years, 9 months ago
I'm having a very strange problem here. After much head scratching and hair pulling, I finally found the source of a long standing exception error in my program - but I have no idea how it is happening. My code to release the context is straight out of Nehe's framework...

if (hRC)											// Do We Have A Rendering Context?
	{
		if (!wglMakeCurrent(NULL,NULL))					// Are We Able To Release The DC And RC Contexts?
		{
			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		}

		if (!wglDeleteContext(hRC))						// Are We Able To Delete The RC?
		{
			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		}
		hRC=NULL;										// Set RC To NULL
	}
the problem is, when the program reaches the wglDeleteContext function call it bombs with an access violation error. I have checked, and the handle being passed in is definitely the one created by the wglCreateContext function at the start of my program. There is only one context and one window in my program. I don't understand why it is crashing here. The context is there, it has been released before the delete call. I simply cannot see why this is going wrong. Can someone enlighten me as to potential causes for this error? What else might cause the context delete to fail so badly?
------------------------------------------[New Delta Games] | [Sliders]
Advertisement
once i got that error when i forgot to put glEnd(); after a glBegin(...);
check your display lists also.
What we do in life, echoes in eternity!
Nope, it isn't that. I'm not using any glBegin/glEnd statements nor am I using display lists.
------------------------------------------[New Delta Games] | [Sliders]
So no-one has any ideas what's causing it? The only drawing operations I'm using are glDrawArrays, glColor and various matrix transformations.

Some other bizarre behaviour has started appearing too, like textures being deleted from video memory without any calls to that effect.

This is really driving me nuts - I can't finish the program if it's going to crash every time someone tries to exit.

Any ideas, no matter how far fetched, would be really appreciated.
------------------------------------------[New Delta Games] | [Sliders]
you will probably have to post more code.

ie; how you are acquiring hrc (the rendering context).
If it isn't the correct pointer, it will bomb out.
This can happen when HRC is set to something that isn't the correct adress.
In your code it will still check.



why don't you try something like this?


HGLRC hglrc;HDC hdc;if ( hglrc = wglGetCurrentContext() ){  hdc = wglGetCurrentDC();  wglMakeCurrent( NULL, NULL );  ReleaseDC( hwnd, hdc );  wglDeleteContext( hglrc );}


or this for less code
HGLRC hglrc;if ( hglrc = wglGetCurrentContext() ){  wglMakeCurrent( NULL, NULL );  wglDeleteContext( hglrc );}


For the record, I use the second version (the cut down one) as I use VCL in a custom class I call glCore.


PS: If it works, please rate me. If it doesn't work, then pelase don't rate me. :)
Beer - the love catalystgood ol' homepage
Nope, they don't work either :( I acquire my hrc with:

if (!(hDC=GetDC(hWnd)))	{		// graceful exit					}if (!(hRC=wglCreateContext(hDC)))	{	       // graceful exit	}


This was all working fine for months. Then for seemingly no reason it started crashing on exit. Debugging leads me as far as the wglDeleteContext call, so I can only assume that the context is undeletable for some reason. Some reason so serious that it causes the program to crash. I don't do anything that would tie up the context though. It's a single threaded program, with one window, one context and no extensions used. Drawing is limited to glDrawArrays and other basic GL functions. I don't use display lists or begin/end pairs. I just cannot think of anything that might be tying up the context like that. Nor can I think of any other reason why it might bomb on context delete :(

And as I said in the beginning, the hrc handle is definitely the correct value. I followed it from creation to deletion and it doesn't change.
------------------------------------------[New Delta Games] | [Sliders]
check the source of sdl (www.libsdl.org) to see what it does
I looked through the SDL code and it does exactly the same as I have been doing and as has been suggested above. I doubt the problem is in the actual exit code, I think the problem lies elsewhere, I just have no idea what might be generating a situation like this. I need some ides of the sort of situations that might result in a failure to delete the context.
------------------------------------------[New Delta Games] | [Sliders]
HI i am experiencing this problem for quite some time as well.
i first noticed it was when i fire up a D3D application in debug mode, then shutting it down. Then if i fire up the opengl app, and try to shutdown, it will crash on the deletecontext(), apparently i think ATI drivers are responsible for this problem...

THX!
Edwinz
Not unless the same problem is in the NVidia drivers too. I don't have ATI on my system. I've searched through this forum and other forums, and the general consensus seems to be that the context gets tied up with certain operations and cannot be deleted until these operations are completed/exited. Alas, I cannot find what might be causing it in my code. I don't use any operations that "tie up" openGL.

Does anyone know of any commands that could check if the context is in use, or perhaps force the context to stop being used?
------------------------------------------[New Delta Games] | [Sliders]

This topic is closed to new replies.

Advertisement