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:
Here's the simple code I'm using to populate the paths:
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");
}
About the author
#2
function gamePiece::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if(isObject(%srcObj)
%srcObj.safeDelete();
}
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();
}
Torque Owner Matthew Harris
%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!