Game Development Community

Random crashes in onCollision() callback

by Bucko · in Torque Game Builder · 04/03/2005 (2:55 pm) · 7 replies

Game sometimes crashes when executing my callback script. Somewhere up the callchain of the crash we are in compiledEval.cc line 442:

gEvalState.pushFrame(thisFunctionName, thisNamespace);
for(i = 0; i < argc; i++)
{
StringTableEntry var = U32toSTE(code[ip + i + 6]);
gEvalState.setCurVarNameCreate(var);
gEvalState.setStringVariable(argv[i+1]);
}

'thisFunctionName' == "onCollision" and 'i' == 2
argv[0] == "onCollision"
argv[1] == 1237
argv[2] == 1235
argv[3] == NULL and this is why 'gEvalState.setStringVariable(argv[i+1]);' crashes.
argv[4] == NULL
argv[5] == 0.00811891
argv[6] == "-0.707106 -0.707106"
argv[7 == 1

Guesses on my part
==============
My onCollision callback worked when I used clearTile(); to remove the tile (tile not deleted until next frame?)
When I switched to setStaticTile(); and setTileCollisionActive(); these random crashes started to happen.
My guess is that T2D sometimes doesn't like an object turning off its collision active status in mid collision. If this is deferred until the next frame maybe it works. I'll check what happens if I store the tiles to be removed and remove them by a scheduled function instead of inside the callback.

#1
04/05/2005 (4:18 am)
The crashes went away when I stopped modifying the tilemap in the callback. Instead, I waited for the callback to finish before changing tile frames/animations/collision status. Still a bug though, or at least a warning about what is safe and what isn't in the onCollision callback.
#2
04/05/2005 (5:17 am)
Interesting. Could you tell me what modifications you were doing to the tilemap so that I can investigate?

There is a known issue with certain functions which is down to be resolved.

Thanks,

- Melv.
#3
04/05/2005 (1:36 pm)
I call setTileCollisionActive() and setStaticTile();
At first I thought setTileCollisionActive() was the culprit but after commenting them out the crsahes still ocurred so setStaticTile() can also cause a crash. After moving them out of the callback the crashes stopped.
In all cases, the crashes ocurred due to missing parameters when gEvalState.setStringVariable(argv[i+1]) was called by T2D as in my original post.
#4
04/06/2005 (2:43 am)
Thanks,

I've added this to the bugs list.

- Melv.
#5
04/09/2005 (9:39 am)
After an initial investigation I have discovered what the problem is.

When a object causes a potential collision with a tile-layer, the tile-layer is given the region of the object (including it's projected velocity) and returns a potential collision set of objects. This PCS is then check sequentially and contains details for handling sub-object collisions of objects. This is an abstract process and is handled this way for any T2D objects that have sub-object collisions.

The problem comes when that set is changed during the onCollision call.

Two options...

1) Queue-up "onCollision" callbacks until all objects have been tested.
2) Enumerate original PCS getting retrieving sequentially potential collision objects.

This will take further work but does impact how any object will handle this in the future. This is an oversight on my part but isn't that difficult to resolve.

Anyway, thanks for the heads-up and I'll post back here with my results.

- Melv.
#6
05/04/2005 (5:17 pm)
Just curious, was this ever resolved? Seems a pretty common thing to change the tile when it is collided with.
#7
05/05/2005 (1:27 am)
Changes to fix this need the new file-format. It will be fixed, yes.

There are several other susceptable areas that have been identified as well.

- Melv.