LoadLevel() crashing TGB
by Eric Robinson · in Torque Game Builder · 04/18/2007 (10:31 pm) · 3 replies
I've looked at this already. My problem is different. I have the following function defined:
// This function says what to do when the main menu "Play" button is pressed.
function playButtonMainMenu()
{
// End the menu level.
sceneWindow2D.endLevel();
sceneWindow2D.resetSceneGraph();
// Load the Intro.
sceneWindow2D.loadLevel($Level::directory @ "intro.t2d");
}Problem is that running that code crashes my TGB (when running from within the level editor - i.e. hit the play button). I added sceneWindow2D.resetSceneGraph() to see if that fixed the crashing but it hasn't. Anyone have any idea?
#2
...
...
Oh. I know why.
Here's the function that called my playButtonMainMenu() above:
Thanks for the quick reply. Helped a lot! Schedule() to the rescue again!
04/18/2007 (11:19 pm)
@Igor: I just did that and it seems to do the trick. Why is that!?...
...
Oh. I know why.
Here's the function that called my playButtonMainMenu() above:
// The playButton was clicked.
function playButton::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
// Fade out music.
$Audio::layer0.SetFadeDuration(0.75);
$Audio::layer0.EnableFade(true);
$Audio::layer0.Stop();
// Call the level manager dispatch.
playButtonMainMenu();
}Boom. The function I called may not have been a function attached to the playButton but it was called from within a playButton function (to which control flow returns after the levelLoad() finishes). And guess which t2dSceneGraph the playButton is in... yup! The one getting removed from sceneWindow2D. Tricky stuff... tricky, tricky stuff.Thanks for the quick reply. Helped a lot! Schedule() to the rescue again!
#3
This is by design. Sometimes you can use safeDelete(). Technically it does a same thing.
04/19/2007 (10:43 pm)
Yeah, thats right! You should return control to engine before you call any script whitch can destroy the caller :)This is by design. Sometimes you can use safeDelete(). Technically it does a same thing.
Torque Owner Igor Kuryatnikov