wglDeleteContext acting weird

I’ve searched the forums on strange behaviour of the DeleteContext, but i couldn’t find a good answer or idea on it. So, in the finishing part of the app, when window is destroyed, i call the usual functions to deinit gl (makecurrent(null, null) and wgldeletecontext(hrc) and the others). The strange part is that this method works very well on most of the cases, but in some of them (usually huge maps with many textures) deletecontext simply crush - i test if the makecurrent succeed or hrc is valid, i also call glfinish. Another thing is that everything is ok if i use a console app that creates the gl window, but the crushes appear in a mfc app that cand preview some scenes.

Sorry if this seems stupid, but i haven’t got a clue.

In which overridden method of CWnd are you calling wglDeleteContext?

The closing method is called when a “stop” flag is set. This is modified when WM_DESTROY, WM_QUIT are received or ESC is pressed.

Try not to set a stop flag when your app receives a WM_DESTROY, but to immediately destroy the context there. Your window, and therefore also the associated device context, is probably already destroyed when you call wglDeleteContext and that probably causes the crash. Hard to tell really without being able to debug your code though.

I take care of WM_DESTROY. It’s not from there.

You said it happens on big maps with lots of textures? Do you delete all of the textures before deleting the context? I’m not sure that it matters, but I would try it just to be safe…

In fact was from the texturing: i was deleting the textures, but some of them were “corrupted” - with more tests i solved it. Anyway, thanks for your answers.