Collision Issue and Removing Objects
Collision Issue and Removing Objects
I am having a problem with sio2sensor and the collision callback system. There was a post with a similar issue (https://sio2interactive.forumotion.net/sio2-engine-f3/use-object-only-for-collision-t115.htm?highlight=collision) but no solution was posted. If I try to remove the sio2sensor in the collisionCallback I get a crash in sio2PhysicCollisionCallback every time.
My collision callback in it's simplest form is here:
The sensor loop in sio2PhysicCollisionCallback starts like this:
It appears as though the problem lies in the while loop. The first iteration through the while loop i = 0 and _SIO2resource->n_sensor = 1 so the loop condition passes as it should. i gets incremented at the bottom of the loop making i = 1. _SIO2resource->n_sensor gets decremented by the sio2SensorFree() call so it is equal to 0. 1 != 0 passes the while condition and we get an endless loop and a buffer overrun in there.
Perhaps the loop should be:
My other issues comes with object deletion. What is the correct way to completely remove an sio2object from a scene and when should it be done (before or after the render loop I assume)? I have tried various things and the closest I have come is:
It appears that freeing the object may leave some remnants of some sort...
My collision callback in it's simplest form is here:
- Code:
void collisionCallback( void * )
{
// Destroy the sensor
SIO2sensor *_SIO2sensor = ( SIO2sensor * )sio2ResourceGet( sio2->_SIO2resource, SIO2_SENSOR, "mySensor" );
_SIO2sensor = sio2SensorFree( _SIO2sensor );
}
The sensor loop in sio2PhysicCollisionCallback starts like this:
- Code:
unsigned int i = 0;
while( i != sio2->_SIO2resource->n_sensor )
{
It appears as though the problem lies in the while loop. The first iteration through the while loop i = 0 and _SIO2resource->n_sensor = 1 so the loop condition passes as it should. i gets incremented at the bottom of the loop making i = 1. _SIO2resource->n_sensor gets decremented by the sio2SensorFree() call so it is equal to 0. 1 != 0 passes the while condition and we get an endless loop and a buffer overrun in there.
Perhaps the loop should be:
- Code:
while( i < sio2->_SIO2resource->n_sensor )
My other issues comes with object deletion. What is the correct way to completely remove an sio2object from a scene and when should it be done (before or after the render loop I assume)? I have tried various things and the closest I have come is:
- Code:
// Remove the object from the physics world
sio2PhysicRemoveObject( sio2->_SIO2physic, someObject );
// Delete object from the resource manager
sio2ResourceDel( sio2->_SIO2resource, SIO2_OBJECT, someObject );
sio2ObjectFree( someObject );
It appears that freeing the object may leave some remnants of some sort...
uprise78- Posts : 228
Join date : 2008-10-31
Similar topics
» Collision objects without rotation
» How to refer to collision objects
» SIO2 1.4 is around the corner...
» duplicating objects at runtime and changing textures on the duplicated objects
» erratic problem exporting and rendering
» How to refer to collision objects
» SIO2 1.4 is around the corner...
» duplicating objects at runtime and changing textures on the duplicated objects
» erratic problem exporting and rendering
Permissions in this forum:
You cannot reply to topics in this forum