Unhandled exception when closing window... SOMETIMES...

Started by
5 comments, last by smitty1276 20 years, 3 months ago
--If I click on the X to close the Window I get an error. --If I depress Alt-F4, I get an error. --If I right click on the bar in the taskbar and select "Close" I do NOT get an error. --If I right click on the icon in top left of window and select "Close" I do NOT get an error. In Windows message terms, is there a difference between the different ways of closing the window? I am also tinkering with directinput and have a keyboard and a mouse device interface, but they are UnAcquired at the point the window closes... I have traced through it, but can''t seem to trace into the exception. Any ideas at all?
Advertisement
What error are you getting?

------------------------------------------
Sometimes, you just can''t win.
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
Unhandled exception in GL.exe(NTDLL.DLL):0xC0000005:Access Violation.

But I only get it when I try to close the window with Alt-F4 or the ''X'' button on the window. Using the context menus, as mentioned before, does not generate the error.
Are you doing something strange in your WndProc()?
I'm not doing much at all, to be honest... this is just a little test to make sure my DirectInput and Sound stuff works...

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ){	static HDC		hDC;	//window device context	static HGLRC	hRC;	//GL rendering context		switch (message)	{		case WM_CREATE:	    Input = new CInputSystem(g_hInstance, g_hWnd);							Input->Initialize();							Input->AcquireDevices();										Sound = new CSoundSystem();							Sound->Initialize();							Sound->LoadSound("c:\\Windows\\Media\\Windows XP Startup.wav");							Sound->Play();							hDC = GetDC(hWnd);							hRC = wglCreateContext(hDC);							wglMakeCurrent(hDC, hRC);							break;		case WM_CLOSE:		wglMakeCurrent(hDC, hRC);							wglDeleteContext(hRC);							Input->Kill();							PostQuitMessage(0);							return 0;							break;									default:			break;	}	return (DefWindowProc(hWnd, message, wParam, lParam));}


[edited by - smitty1276 on January 9, 2004 5:22:57 PM]
I see some problems.. I''ll answer what''s wrong first: you should put PostQuitMessage() in WM_DESTROY, not WM_CLOSE. Returning 0 on WM_CLOSE prevents it from closing (I think. Or it may let it close.)

Secondly, don''t initialize things in WM_CREATE. Do it somewhere in main(), or before your message loop. Just don''t do it in WM_CREATE.

Third, this may not apply, but if you ever think about having more than one window with that WndProc, then static variables will break it. Make them global or something if you think you''ll ever have multiple OpenGL windows.
Thanks... I''ll play around with that a bit.

This topic is closed to new replies.

Advertisement