Program hangs on quit()
by Bryan Edds · in Torque Game Builder · 06/19/2005 (11:31 pm) · 8 replies
I have a call to quit() in my code. All it does is hang the engine with an infinite loop right when it is evaluated (infinite loop takes place in CodeBlock::exec function). Anyone had this problem before?
#2
quit(); from the console works, and works from all the other places that are used in the code.
The line of code before the quit() call is an error() function call which does sucessfully output the message to the screen. I have traced into the engine code - the infinite loop is on the execution of the quit CodeBlock.
06/20/2005 (2:15 am)
Using WinXP no service pack.quit(); from the console works, and works from all the other places that are used in the code.
The line of code before the quit() call is an error() function call which does sucessfully output the message to the screen. I have traced into the engine code - the infinite loop is on the execution of the quit CodeBlock.
#3
If you've got modifications running then the only thing I can think of would be to look at potential callbacks when shutting down where the "quit()" command is being used. Other than that, I'm out of ideas.
Sorry I can't think of anything more. :(
- Melv.
06/20/2005 (3:37 am)
I presume this happens on a stock v1.0.2 release if you're reporting as a bug in T2D? If so, that's very wierd indeed. The "Quit" command from the menu just calls "quit();" so is this one hanging as well?If you've got modifications running then the only thing I can think of would be to look at potential callbacks when shutting down where the "quit()" command is being used. Other than that, I'm out of ideas.
Sorry I can't think of anything more. :(
- Melv.
#4
What do you think would happen here? -
while(true) quit();
Would you think it would exit the program? You'd be wrong. If you try to quit in an infinite loop, you're just going to lock up. The reason that I was quitting the app was in order to avoid an infinite loop. But this did not cut it.
The only way to get it to work was to set a quit flag and break the loop on the quitting condition, then testing the flag after the loop, and quitting then when necessary.
Not intuitive... but not a bug either, I don't think. Hard to say what it is. Oh well, it works great now with the %quitFlag, so yay!
06/21/2005 (2:38 am)
Aha! I figured it out -What do you think would happen here? -
while(true) quit();
Would you think it would exit the program? You'd be wrong. If you try to quit in an infinite loop, you're just going to lock up. The reason that I was quitting the app was in order to avoid an infinite loop. But this did not cut it.
The only way to get it to work was to set a quit flag and break the loop on the quitting condition, then testing the flag after the loop, and quitting then when necessary.
Not intuitive... but not a bug either, I don't think. Hard to say what it is. Oh well, it works great now with the %quitFlag, so yay!
#5
Glad it's working Bryan. :)
- Melv.
06/21/2005 (4:23 am)
Ooh, that code-statement makes my head hurt! ;)Glad it's working Bryan. :)
- Melv.
#6
If you execute the following function from the console you do not see each loop iteration scrolling through the console window as it is processed but rather the whole result appears upon completion(eventually, be patient... or lower the loop limit).
It would seem that the simulation is held up until the current script has completed hence in your example the loop never completes so the simulation never gets chance to honour the quit request issued from within the script.
The following also fails (in my tests) for the same reason when inserted into a script file:
Similarly if you add echo( "T2D Rocks!" ); to main.cs at line 409 in the example project e.g.:
and then launch T2D with the -help option (which will issue a quit() request prior to the echo statement) you will still see the message in the console.log. It appears that the whole script file is processed before the quit() request can be honoured.
Can anyone with more knowledge of the script engine confirm or correct this theory?
06/21/2005 (4:42 am)
I don't think it's strange quit() behaviour as such. I think it has to do with the way that scripts in general are handled within Torque.If you execute the following function from the console you do not see each loop iteration scrolling through the console window as it is processed but rather the whole result appears upon completion(eventually, be patient... or lower the loop limit).
function test()
{
echo( "test() entered..." );
for( %i=0; %i < 100000; %i++ )
{
echo( %i );
}
}It would seem that the simulation is held up until the current script has completed hence in your example the loop never completes so the simulation never gets chance to honour the quit request issued from within the script.
The following also fails (in my tests) for the same reason when inserted into a script file:
quit();
while( true )
{
// Whatever
}Similarly if you add echo( "T2D Rocks!" ); to main.cs at line 409 in the example project e.g.:
// Display Help.
displayHelp();
// Quit!
quit();
}
else
{
// Start-up the script mods.
onStart();
// User Info.
echo("T2D Engine initialized...");
}
echo( "T2D Rocks!" );and then launch T2D with the -help option (which will issue a quit() request prior to the echo statement) you will still see the message in the console.log. It appears that the whole script file is processed before the quit() request can be honoured.
Can anyone with more knowledge of the script engine confirm or correct this theory?
#7
06/21/2005 (7:39 am)
You are essentially correct, yes.
#8
06/21/2005 (10:19 am)
Thats why when trying to acheive the typical "looping" behavior we use schedules :)
Torque Owner Philip Mansfield
Default Studio Name
If you enter quit(); from the console, does that work OK?
Do you have other code that executes prior to the quit() statment? If so, stiick some echo statements in and see where it gets hung up.