Game Development Community

Paths causing TGB to crash

by Conor O Kane · in Torque Game Builder · 05/03/2007 (6:18 am) · 15 replies

I'm using path objects to move enemies along smooth splines for my game. I would like to have my enemies delete themselves when they reach the end of their path, unfortunately there's no callback methods for paths so I though I'd just extend the path beyond the enemy's world limits and let them die from their onWorldLimit callback.
But when I try this TGB crashes when the enemies leave the screen.
Are paths bugged or is there special rules about using them. Do I have to detach things before I delete them? Is there any way to get around the lack of callbacks on paths?

#1
05/03/2007 (6:31 am)
Can you post example script please so I can repro this?
#2
05/03/2007 (6:43 am)
The problem seems to go away when I define the path in code with the %path = new t2dPath function, rather than drawing them in the editor. That'll work fine - I was just using the editor drawn path for testing anyway.
#3
05/03/2007 (6:45 am)
Sounds odd. How are you deleting your objects?

(By the way, TGB 1.5 added path callbacks!)
#4
05/03/2007 (6:47 am)
Gah - I spoke too soon, it's happening again.

I'm deleting my objects in the onWorldLimits callback with %this.safeDelete();

Will the new TGB be able to import and run current projects?
#5
05/03/2007 (7:03 am)
@ Neo : here's the function where I create my wave of enemies and their path:

function levelManager::spawnPathWave(%this, %waveNumber, %numberOfEnemies, %delayTime, %node0, %node1, %node2, %node3)
{
	// create the wave of enemies
	
	%newWave = new t2dSceneObject()
	{
		class = enemyWave;
		numberOfEnemies = %numberOfEnemies;
	};
	
	// create the path for them to follow
	
	%newWave.Path = new t2dPath()
	{
		scenegraph = $pDrone.scenegraph;
		pathType = "catmull";
	};
	
	%newWave.Path.addNode(%node0, 0);
	%newWave.Path.addNode(%node1, 1);
	%newWave.Path.addNode(%node2, 2);
	%newWave.Path.addNode(%node3, 3);
	
	
	// create the enemies in the wave
	
	for (%i = 1; %i <= %numberOfEnemies; %i++)
	{
		%newWave.enemy[%i] = %this.spawnEnemyChopper(%newWave);
		%newWave.enemy[%i].parentPath = %newPath;
		%newWave.enemy[%i].setPosition(800, 0);                       
		%newWave.enemy[%i].schedule((%i -1) * %delaytime, "attachToPath", %newWave.Path, 3); 
	}
		
	%this.wave[%waveNumber] = %newWave;
}

and here's how I attach them to their path:

function enemy::attachToPath(%this, %targetPath, %endNode)
{
	%targetPath.attachObject(%this, %this.speed, 1, 0, %endNode, "wrap", 1, true);
}
#6
05/03/2007 (9:52 am)
K looking into it
#7
05/03/2007 (10:06 am)
I created a spline path and mounted a sprite to it, setting its world limit to kill made sure that the path would take it outside its world limit. Works fine, sprite goes outside world limit and is removed.

I suppose I should have asked what version you are using as I am testing with beta 3 and this might have been fixed if youre using an older version?
#8
05/05/2007 (8:44 pm)
Thanks for looking in to it Neo - I'm using TGB 1.1.3

The problem seems more complex than I first thought. I'm spawning a wave of 4 enemies who travel along the spline. If I shoot and kill the first 2 enemies then TGB crashes, or if I let them wander off the screen into their world limits, crash. However, if I shoot the 2nd two enemies and let the first 2 hit their world limits, the game does not crash. Unfortunately I can't use any echo commands to debug as it's just crashing with the standard windows 'send error report' crash. Perhaps I need to look into running a debug build of TGB and stepping through the code. I was hoping I wouldn't need to resort to that yet :-(
#9
05/06/2007 (7:45 am)
Any particular reason you're sticking with 1.1.3 and dont want to move to beta3?

My guess is that it might be related to the bug where objects being updated after they were destroyed which causes a crash.

I'll look into it and let you know how it goes.
#10
05/07/2007 (4:10 am)
Neo - I'm just getting started with Torque, this is my first program, so I thought I'd stick with the released version as the documentation would be more accurate than the Beta version. I guess I'll switch to the new version once it's ready.
#11
05/09/2007 (6:01 am)
I have this same problem, but no fix. I think it has to do with deleting an object attached to a path and the path not *realizing* it... which would be a great theory, if it happened every time- except that if your bug is like mine, it is consistent only in that it always eventually occurs.

What you may want to do, and what I haven't had time to, is give each object on the path a reference to the path and in their OnWorldLimit callback have them explicitly detach themselves from the path before they delete themselves. I believe that deleting the path as well (and adding a or cloning a new path with each object instantiation) may also solve the problem, but again, I have been working on other things and have not had time to try it out.

Lemme know if it works!
#12
05/09/2007 (6:08 am)
Samuel - I tried detaching the objects from the path before deleting them, but the crash happened exactly as before.

I've given up on paths and have got around the problem by using a combination of MoveTo and mounting with a weak mount force to get smooth movement. If paths are more stable in the new version (and it sounds like they are) then I'll probably revisit them then.
#13
05/09/2007 (6:11 am)
Sounds good. If I manage to figure out a fix (don't hold your breath) I'll post it somewhere or other.
#14
05/09/2007 (10:31 pm)
Deleting of a object in onReachNode callback isn't such a good idea.
Becuase the way how the engine walks through an attached objects, so even if you detach object and delete them before the callback returns you get a crash(probably). Solution is simple. Use schedule function with time 0 and delete your object in another function. (you should detach object first in callback though)
#15
05/10/2007 (7:14 am)
Thanks Igor, I'll give that a shot next time I use paths.