FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

What is the Correct Way to Delete an SIO2Object?

3 posters

Go down

What is the Correct Way to Delete an SIO2Object? Empty What is the Correct Way to Delete an SIO2Object?

Post  uprise78 Mon May 04, 2009 9:53 am

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 );

Something is missing in there because I get a crash in the render loop...

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  sio2interactive Mon May 04, 2009 4:20 pm

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.
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  uprise78 Mon May 04, 2009 5:11 pm

I just setup a simple sensor and in the collision callback I do this:

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 );

What is the Correct Way to Delete an SIO2Object? Gdb

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  sio2interactive Mon May 04, 2009 5:34 pm

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...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  uprise78 Mon May 04, 2009 7:02 pm

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

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  sio2interactive Mon May 04, 2009 7:24 pm

Nope... its because you delete the sensor inside its callback... (the other possible reason its something happen before that). Use malloc debug...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  uprise78 Tue May 05, 2009 1:00 pm

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?

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  sw Fri May 08, 2009 9:53 am

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
sw

Posts : 73
Join date : 2008-10-12

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  uprise78 Fri May 08, 2009 10:49 am

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

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  sw Fri May 08, 2009 11:11 am

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
sw

Posts : 73
Join date : 2008-10-12

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  uprise78 Fri May 08, 2009 11:31 am

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:

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

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  sw Fri May 08, 2009 12:45 pm

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
sw
sw

Posts : 73
Join date : 2008-10-12

Back to top Go down

What is the Correct Way to Delete an SIO2Object? Empty Re: What is the Correct Way to Delete an SIO2Object?

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum