Another problem - DestroyWindow(hWnd) causes error

Started by
13 comments, last by joanusdmentia 19 years, 4 months ago
Hello, there is another problem that is not that bad, but I think it could indicate that somewhere else something is going wrong. When I try to close my program, all the OpenGL-terminating stuff works fine, except for the "DestroyWindow(hWnd)" call. Calling this function the program gives out an access error and closes. What could be the reason for that error? I de-initialised everything dealing with OpenGL before, but this error still appears... ...thanks in advance, Marco
Advertisement
Most likely you're corrupting the heap somewhere. Double check all your pointers and arrays to check you're not making invalid accesses anywhere. Also run your program through a debugger and watch the value of hWnd to see if it gets changed anywhere.

Enigma
I checked everything, but I did not find anything. Seems that I did not so see samoething, as the crash is still there.

In the meantime I have tried some memory-leak-finding-programs, but one did not work (just crashed at a normal new command) and the other does not display that many information I want to have.

Perhaps someone of you can recommend such a program? :)
I don't think you need such a program.
The problem, most likely, lays in your code (I had something like this myself), so I'd rather look for errors in the creation of the window.
If you're calling DestroyWindow() after the main message-processing loop (the one with the GetMessage or PeekMessage), then you're calling it AFTER the window is already destroyed!

Normally, the main loop finishs when the WM_QUIT message is received. A WM_QUIT message is posted by the function PostQuitMessage(), that "is typically used in response to a WM_DESTROY message" (according the MSDN). Finally, DestroyWindow() is the default procedure in response to a WM_CLOSE message (if the user confirms the exit).

With that all in mind, I think there is no need to call DestroyWindow() after the main loop. Although, you probably have a hDC=GetDC(hWnd); somewhere before the main loop (at least, I have that line)... and if you try to call ReleaseDC(hWnd,hDC); it will fail. I have that problem and I'm still looking for a good solution; because moving the OpenGL initialization/termination inside the WndProc seemed to not work for me (that was some time ago and I can't remember the details, I'll try to do it again soon).

If you find a good solution to this problem, please let me know.
theNestruoSyntax error in 2410Ok
In my program, there are two ways to quit the program: press alt+F4 (or just shut it somehow from windows) or simply press the escape key. This makes the main loop ending and after that the shutdown process begins. So, in fact there is not PostQuitMessage() call or a WM_CLOSE message or anything.

But the problem still exists, so I guess the problem can be found elsewhere... I'll check my window initialising code when I am at home.
Quote:Original post by Anonymous Poster
In my program, there are two ways to quit the program: press alt+F4 (or just shut it somehow from windows) or simply press the escape key. This makes the main loop ending and after that the shutdown process begins. So, in fact there is not PostQuitMessage() call or a WM_CLOSE message or anything.

Wrong. Pressing Alt-F4 will trigger a WM_CLOSE event, which as has been mentioned will by default destroy the window.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Quote:Original post by joanusdmentia
Wrong. Pressing Alt-F4 will trigger a WM_CLOSE event, which as has been mentioned will by default destroy the window.

Sorry, misunderstanding.

I meant that one way to close the program is to press alt+f4 or close it somehow different over windows. This all results in the WM_CLOSE message as you said.

But another way is to press the escape key. This simply tells my program to leave the main loop and begin with the terminating process. So by that way, there is no WM_CLOSE message, but the error still appears...

Edit: I have now commented out all parts of my programm except for the initialising and de-initialising part, but the DestroyWindow() call still causes a crash.
Thus I think the error is to be found in the initialising code (where else could it be? ;) ), but after comparing it to the code from NeHe's tutorial #1 I did not find any important differences.

So, I am really confused... what could be the reason for that error?

[Edited by - Marco H on December 3, 2004 11:12:47 AM]
Ah, OK :)

Well, there are only 2 possible things I can think of that might cause it.
1) The window is already destroyed (unlikely)
2) The window handle is invalid

Now, I doubt you forgot to set the window handle in your code since everything else is working. It could still be modified if you overflow a buffer though. Try stepping through the code, taking note of the window's HWND immediately after you create it, and then compare that against the HWND just before you destroy the window. If they're different, odds are you have a buffer overflow somewhere. And if not....err..... *shrugs*.

Also, how much code are we talking here? It would be alot easier if you could post the relevant parts.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Quote:Original post by joanusdmentia
Try stepping through the code, taking note of the window's HWND immediately after you create it, and then compare that against the HWND just before you destroy the window. If they're different, odds are you have a buffer overflow somewhere. And if not....err..... *shrugs*.

Ok, stupid question maybe, but how do I check the value of hWnd? What type is HWND? A structure? I tried to google it, but I found nothing...

Quote:Original post by joanusdmentia
Also, how much code are we talking here? It would be alot easier if you could post the relevant parts.

At the moment I have exactly 2167 lines of code (without comments or blank lines, only the real code ;) ), but the initialising and de-initialising parts are not that different from those of NeHe's tutorials. In fact it is mostly the same...

For testing I commented everything out in the WinMain function, so that only the window init and de-init part is compiled, but the error remains.
If I would know how to check the value of hWnd it would be easier =)

This topic is closed to new replies.

Advertisement