Game Development Community

Engine Crash when calling safeDelete()

by Vance Souders · in Torque Game Builder · 11/07/2006 (3:47 pm) · 2 replies

I'm moving sprites along three different path objects, with each path going from the right side of the screen to the left. I want to delete the objects when they reach the end of the path so I'm using a scene object located at the end of each path to test for collision. In the collision callback, I'm calling safedelete on the moving sprite. Occasionally, this causes the engine to crash with an access violation. It's exploding at line 44 in t2dVector.h. Any ideas what might be causing this behavior?


Here's the code I'm using to delete the sprites:



function gamePiece::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
%srcObj.safeDelete();
}



Here's the simple code I'm using to populate the paths:



function gameState::spawnPieces(%this)
{
%next_lane = %this.getAvailableLane();

%sprite = new t2dStaticSprite() { class = "gamePiece"; config = "gamePieceDatablock";
imageMap="path_finderImageMap"; scenegraph = gamescenegraph; };

%sprite.frame = getRandom(0,17);

%sprite.Initialize(%next_lane);

switch(%next_lane)
{
case(0):
lane_one.attachObject(%sprite, 10, 0, 1, 0, "WRAP", 1, true);
lane_one.setOrient(%sprite, false);
case(1):
lane_two.attachObject(%sprite, 10, 0, 1, 0, "WRAP", 1, true);
lane_two.setOrient(%sprite, false);
case(2):
lane_three.attachObject(%sprite, 10, 0, 1, 0, "WRAP", 1, true);
lane_three.setOrient(%sprite, false);

}

%this.schedule(2000, "spawnPieces");

}


#1
11/07/2006 (10:31 pm)
Ok the first thing is I wouldn't use a scene object to see if your object is at the end of the path. Check the node to see if there is a collision. Less work. Also maybe try dismounting the object before deleting it using dismount() function. I think it may crash because you are referencing the object somewhere else in script when its deleted. You could also do this as a temp fix.

%object.visible = false;
%object.setCollisionActive(false, false);
%object.setCollisionPhysics(false, false);
%object.setCollisionCallback(false);

Basically its like deactivating the object and hiding it but its "still there". Good Luck!
#2
11/09/2006 (6:50 pm)
In your function, try checking if the object exists before deleting it. So, far example, try doing something like this:


function gamePiece::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(isObject(%srcObj)
%srcObj.safeDelete();
}