View previous topic :: View next topic |
Author |
Message |
ParticlePeter
Joined: 19 Nov 2011 Posts: 49 Location: Germany
|
Posted: Fri May 25, 2012 8:39 am Post subject: GLFW: Clean Shutdown with close window icon ? |
|
|
Hi,
I'm using Derelict with GLFW on Win7. Shutting down with the escape key is fine, but with the close window icon I get a Windows error "Application.exe has stop working ... Problem signature: Problem Event Name: APPCRASH"
...
My Setup:
Code: |
void main() {
// GLFW Setup Code
scope( exit ) glfwTerminate() ;
bool running = true ;
while ( running ) {
glfwPollEvents() ;
running = glfwIsWindow( window ) && glfwGetKey( window , GLFW_KEY_ESCAPE ) != GLFW_PRESS ;
...
}
}
|
Is glfwTerminate() called when I use the close icon ?
How can I properly shut everything down when using the close window button ? _________________ Cheers, searching for the Pivot of my Soul, PP |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Fri May 25, 2012 10:52 pm Post subject: Re: GLFW: Clean Shutdown with close window icon ? |
|
|
ParticlePeter wrote: |
Is glfwTerminate() called when I use the close icon ?
How can I properly shut everything down when using the close window button ? |
The call to glfwIsWindow returns false if the window has been closed, so when things are functioning properly, the loop should exit and glfwTerminate should indeed be called in the code snippet you have here. I'm quite certain the problem is not a lack of cleanup. Your app is crashing before it ever has a chance to properly exit, but I have no idea what might be causing it. I suggest you use a debugger. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
ParticlePeter
Joined: 19 Nov 2011 Posts: 49 Location: Germany
|
Posted: Sat May 26, 2012 10:40 am Post subject: |
|
|
Hi Aldacron, thanks for your reply
in fact I am using a debugger, but am not experienced enough to solve the problem. How could I debug it, or what am I looking for ?
I added a line directly after the while loop, and set a breakpoint. This line is not reached when using the close window icon, but it is reached with the escape key.
Code: |
void main() {
// GLFW Setup Code
scope( exit ) glfwTerminate() ;
bool running = true ;
while ( running ) {
glfwPollEvents() ;
running = glfwIsWindow( window ) && ... ;
...
}
writeln( "What Happens Now ?!?" ) ; // NOT REACHED BREAKPOINT
}
|
I changed things in my code at other locations, and now I am getting a access violation exception ( only triggered with the window icon ). The debugger just shows me a disassmbly file and this call stack:
Code: |
> nvoglv32.dll!570f238f()
[Frames below ..., no symbols loaded for nvoglv32.dll]
nvoglv32.dll!570ee876()
nvoglv32.dll!570f1d31()
nvoglv32.dll!570f32c8()
nvoglv32.dll!571aff0b()
kernel32.dll!7577339a()
ntdll.dll!77799ef2()
ntdll.dll!77799ec5()
|
What and how could I proceed with debugging ? _________________ Cheers, searching for the Pivot of my Soul, PP |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sat May 26, 2012 7:44 pm Post subject: |
|
|
Debugging is a skill that you just have to pick up through trial and error. Sometimes you run into dead ends and have to get creative. Sometimes you can spend days debugging a problem, but you'll be more likely to recognize the same sort of problem in the future.
Unfortunately, the call stack you pasted shows it's crashing in your opengl driver, which means it's not immediately obvious where the problem lies. My first assumption is that it isn't an issue with GLFW (though it could possibly be). There are plenty of things that could be going wrong when mixing C with D. For example, you could be clobbering memory somewhere in your code, or I could have a type declaration wrong in the binding (which would affect the size of the type and could cause all sorts of weird behavior on the C side). Either case could potentially show no effect for the entire run of the program, then cause a crash on shutdown.
What I usually do in a situation like this is sprinkle writelns throughout the code. That could help narrow down to what's causing the problem. Sometimes, it can cause the crash to happen elsewhere (as you saw when you changed your code around) which could point to memory corruption. It may also help to comment out blocks of code to help narrow it down further. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
ParticlePeter
Joined: 19 Nov 2011 Posts: 49 Location: Germany
|
Posted: Mon May 28, 2012 5:39 am Post subject: |
|
|
Hi Aldacron,
thanks, your answer helped, I could narrow down the problem. Closing the window with the icon destroys it and I guess the GL context aswell.
Contrary the escape key doesn't destroy the window, it just exits the while loop. After the query I am drawing stuff, which is faulty in the first case, but valid in the second one. Here is my working code:
Code: |
void main() {
// GLFW Setup Code
scope( exit ) glfwTerminate() ;
while ( true ) {
glfwPollEvents() ;
if ( !glfwIsWindow( window ) || glfwGetKey( window , GLFW_KEY_ESCAPE ) == GLFW_PRESS )
break ;
// GL Draw Code
...
}
writeln( "Clean Exit !" ) ; // REACHED
}
|
_________________ Cheers, searching for the Pivot of my Soul, PP |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|