What is the Correct Way to Delete an SIO2Object?
3 posters
What is the Correct Way to Delete an SIO2Object?
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:
Something is missing in there because I get a crash in the render loop...
- 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 );
Something is missing in there because I get a crash in the render loop...
uprise78- Posts : 228
Join date : 2008-10-31
Re: What is the Correct Way to Delete an SIO2Object?
sio2ResourceDel( sio2->_SIO2resource, SIO2_OBJECT, someObject );
>> This will be called automatically with sio2ObjectFree... no need to call it, just remove the object from the physic world and call sio2ObjectFree should do the trick just fine... if not post the GDB output.
>> This will be called automatically with sio2ObjectFree... no need to call it, just remove the object from the physic world and call sio2ObjectFree should do the trick just fine... if not post the GDB output.
Re: What is the Correct Way to Delete an SIO2Object?
I just setup a simple sensor and in the collision callback I do this:
The crash occurs in sio2ObjectRender:
- Code:
void touchGround( void * )
{
// Remove the objects from the physics world
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object0 );
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object1 );
sio2ObjectFree( sensor->_SIO2object0 );
sio2ObjectFree( sensor->_SIO2object1 );
// Destroy the sensor so it will only be executed once.
_sensor = sio2SensorFree( _sensor );
}
The crash occurs in sio2ObjectRender:
- Code:
i = 0;
while( i != tmp->n_vgroup )
{
if( !sio2IsEnabled( tmp->flags, SIO2_OBJECT_TWOSIDE ) )
{
sio2VertexGroupRender( tmp->_SIO2vertexgroup[ i ],
_usematerial );
}
else
{
glCullFace( GL_FRONT );
sio2VertexGroupRender( tmp->_SIO2vertexgroup[ i ],
_usematerial );
uprise78- Posts : 228
Join date : 2008-10-31
Re: What is the Correct Way to Delete an SIO2Object?
The crash have nothing to do with the sensor... its something else... use malloc debug there's maybe a leak somewhere... also try to rebuild your .sio2 from scratch... Also _sensor = sio2SensorFree( _sensor ); this is suspicious... you cannot free an object inside its own callback function... that doesn't make sense...
Re: What is the Correct Way to Delete an SIO2Object?
Is it possible that because I am deleting an instance (object with .001 ext) the crash could occur?
uprise78- Posts : 228
Join date : 2008-10-31
Re: What is the Correct Way to Delete an SIO2Object?
Nope... its because you delete the sensor inside its callback... (the other possible reason its something happen before that). Use malloc debug...
Re: What is the Correct Way to Delete an SIO2Object?
I removed the code to delete the sensor. The only code that gets run in the collision callback is:
I get a crash in sio2ObjectBindVBO when Guard Malloc is enabled. It appears as though the free'd object is being passed in because when I set a breakpoint the object has no properties. Any ideas?
- Code:
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object0 );
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object1 );
sio2ObjectFree( sensor->_SIO2object0 );
sio2ObjectFree( sensor->_SIO2object1 );
I get a crash in sio2ObjectBindVBO when Guard Malloc is enabled. It appears as though the free'd object is being passed in because when I set a breakpoint the object has no properties. Any ideas?
uprise78- Posts : 228
Join date : 2008-10-31
Re: What is the Correct Way to Delete an SIO2Object?
uprise78 wrote:I removed the code to delete the sensor. The only code that gets run in the collision callback is:
- Code:
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object0 );
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object1 );
sio2ObjectFree( sensor->_SIO2object0 );
sio2ObjectFree( sensor->_SIO2object1 );
I get a crash in sio2ObjectBindVBO when Guard Malloc is enabled. It appears as though the free'd object is being passed in because when I set a breakpoint the object has no properties. Any ideas?
do not remove physic object in the physic loop.
sw- Posts : 73
Join date : 2008-10-12
Re: What is the Correct Way to Delete an SIO2Object?
The sio2PhysicRemoveObject is working fine. I am hitting this code at the very end of the render loop and if I just comment out the sio2ObjectFree calls all works as planned so I don't think that is it...
uprise78- Posts : 228
Join date : 2008-10-31
Re: What is the Correct Way to Delete an SIO2Object?
uprise78 wrote:The sio2PhysicRemoveObject is working fine. I am hitting this code at the very end of the render loop and if I just comment out the sio2ObjectFree calls all works as planned so I don't think that is it...
the sensor->_SIO2object0 is not NULL ?
sw- Posts : 73
Join date : 2008-10-12
Re: What is the Correct Way to Delete an SIO2Object?
It is definitely not NULL. This is a very odd one. Duplicating it is pretty easy too. Using Tutorial 06_1 as a base just replace templateScreenTap with:
Add two variable declarations to the top of the file:
At the end of the render loop add:
To duplicate, just triple tap any object. This will add the collision sensor to two of the suzannes. Then just push the suzanne closest to the player into the one on the right. You can double tap the suzanne closest to you to see which one it should be colliding with.
- Code:
void templateScreenTap( void *_ptr, unsigned char _state )
{
if( _state == SIO2_WINDOW_TAP_DOWN && sio2->_SIO2window->n_tap == 3 && selection )
{
duplicate_object = 1;
SIO2object *suz1 = sio2ResourceGetObject( sio2->_SIO2resource, "object/Suzanne" );
SIO2object *suz2 = sio2ResourceGetObject( sio2->_SIO2resource, "object/Suzanne.003" );
sensor = sio2SensorInitCollision( "mySensor", suz1, suz2, touchground );
}
else if( _state == SIO2_WINDOW_TAP_DOWN )
{
// If we double tap it means that we are trying
// to select something.
if( sio2->_SIO2window->n_tap == 2 )
{ tap_select = 1; }
else
{
start.x = sio2->_SIO2window->touch[ 0 ].x;
start.y = sio2->_SIO2window->touch[ 0 ].y;
}
}
else
{
MOV_DIR = 0;
ROT_Z = 0.0f;
}
}
void touchground( void * )
{
remove_object = 1;
printf("touch_ground\n");
}
Add two variable declarations to the top of the file:
- Code:
unsigned char remove_object = 0;
SIO2sensor *sensor;
At the end of the render loop add:
- Code:
if( remove_object && sensor )
{
// Remove the objects from the physics world
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object0 );
sio2PhysicRemoveObject( sio2->_SIO2physic, sensor->_SIO2object1 );
sio2ObjectFree( sensor->_SIO2object0 );
sio2ObjectFree( sensor->_SIO2object1 );
remove_object = 0;
sensor = NULL; // Just to make sure we never get here again
}
To duplicate, just triple tap any object. This will add the collision sensor to two of the suzannes. Then just push the suzanne closest to the player into the one on the right. You can double tap the suzanne closest to you to see which one it should be colliding with.
uprise78- Posts : 228
Join date : 2008-10-31
Re: What is the Correct Way to Delete an SIO2Object?
Your Suzanne Suzanne.003 deleted, and your Suzanne.002 still in rendor loop ?
maybe the problem is Suzanne.002 depends on the Suzanne.
and maybe another problem is the n_tap==2 will be first excute than the n_tap==3
maybe the problem is Suzanne.002 depends on the Suzanne.
and maybe another problem is the n_tap==2 will be first excute than the n_tap==3
sw- Posts : 73
Join date : 2008-10-12
Similar topics
» How do I delete a resource?
» Correct way to remove SIO2sensor?
» how to correct sio2widget area using portrait ??
» SIO2object::col
» rad in SIO2object
» Correct way to remove SIO2sensor?
» how to correct sio2widget area using portrait ??
» SIO2object::col
» rad in SIO2object
Permissions in this forum:
You cannot reply to topics in this forum