PDA

View Full Version : wglDeleteContext crashes app, and background color



cyrfer
01-23-2012, 01:05 AM
Hi,
I have some basic GL code working very well on Windows 7 + NVIDIA. The same code has different behavior on Windows Vista + Intel 945GM. My code used to work on both platforms, so I think I have a fundamental issue which I'm having trouble to find.

The first noticeable symptom is that the screen shows only the background color assigned to the registered WNDCLASSEX. I do not see any of the objects I draw and attempts to set the clear color are not changing the screen color.

The next symptom is that the app crashes when I cleanup with wglDeleteContext(rc).

I think something is flawed in my basic setup, but after researching for hours I do not see any difference with what is recommended and my code. My setup does the following:
1- register a class and create a window
2- get the device context
3- enumerate the pixel formats with DescribePixelFormat
4- use choosepixelformat and setpixelformat to setup the DC.
5- wglCreateContext & wglMakeCurrent

Does anyone see how it is possible for the background color to show or why destroying the render context causes a crash?

On a side note, I also made a temporary window and a temporary render context after the application created its regular window. The handle for the temporary context is 0x00010000. Destroying this context does not cause a crash. Then my app continues, and the render context created from the application's window is 0x00020000, but again destroying this context DOES cause a crash. Why would using a different window to a create a context not also cause a crash?

Thanks for any tips.

Leith Bade
01-24-2012, 07:05 PM
Do you do a wglMakeCurrent(NULL) before you delete the context?

V-man
01-25-2012, 12:29 PM
You can try the steps here and see if it helps.
http://www.opengl.org/wiki/Platform_specifics:_Windows#When_do_I_destroy_the_ GL_context.3F

cyrfer
01-28-2012, 12:12 PM
Hi guys,
Yes, I've followed protocol when destroying the context. Like I said, I destroy the 1st context with no problems and this stuff all works fine on NVIDIA. :( Thanks for the suggestions.

cyrfer
01-28-2012, 02:07 PM
I was able to get a little more info from gDEBugger. It says an error occurred when I create my 2nd GL context. gDEBugger must register something to catch that info because I see 0x00020000 returned from wglCreateContext and wglMakeCurrent(0x00020000) return TRUE (in my application).

Does the fact that gDEBugger shows I have an error when creating my 2nd context give any hints? Again, it seems like maybe I did not delete my 1st context properly, and I've tried the variations in the link posted by V-man.

To summarize again, only gDEBugger reports an error. However, my app does not run properly (cannot clear buffers, VBOs are NULL) and it crashes when destroying the HGLRC.

Accept for the fact that I create a temporary window and HGLRC to detect the capabilities before creating the window and HGLRC that my app will use, this is an extremely minimal GL application using the "Intel 945GM" renderer.

Here is the code I am using to create / destroy my HGLRC:
class GLContext
{
private:
DECLARE_REF_COUNTING
RefPtr<DeviceContext> _dc;
HGLRC _hglRC;

/// not implemented by design
GLContext();

public:
GLContext(RefPtr<DeviceContext>&amp; dc)
: INIT_REF_COUNT
, _dc(dc)
, _hglRC(NULL)
{
_hglRC = ::wglCreateContext( _dc->GetHandle() );
BOOL success_mc = ::wglMakeCurrent( _dc->GetHandle(), _hglRC );
}

~GLContext()
{
// http://msdn.microsoft.com/en-us/library/dd318300%28v=vs.85%29.aspx
if( _hglRC )
{
BOOL success_mc_glrc = ::wglMakeCurrent( _dc->GetHandle(), _hglRC );
BOOL success_mc_null = ::wglMakeCurrent( NULL /*_dc->GetHandle()*/, NULL /*_hglRC*/ );
BOOL success_delc = ::wglDeleteContext( _hglRC );
}
}

IMPLEMENT_REF_COUNTING

const HGLRC GetHandle() const
{
return _hglRC;
}

const RefPtr<DeviceContext> GetDeviceContext() const
{
return _dc;
}
};

cyrfer
02-02-2012, 10:46 PM
Would someone confirm that this is the correct protocol for managing a GL context? It seems obvious to me, but maybe I do not understand something?

Another idea I had is that maybe I am using the wrong format index when creating the original context. Could that be an issue? I enumerate a list of PixelFormatDescriptors using the Windows API. I am arbitrarily choosing one with the highest settings before I create my context.

cyrfer
02-27-2012, 11:27 PM
I'm pretty sure I figured out the problem. It had nothing to do with GL. I was logging with a wostringstream and I think I added too much to the SS. It must have tripped some error and everything went wack. I'm lucky I found it. The only clue I had was that my log file was incomplete.