Testing and failing Object duplication

View previous topic View next topic Go down

Testing and failing Object duplication

Post  iphoniac on Thu Dec 11, 2008 5:57 am

Hello everybody.

Im running some tests with tutorial06_1 in the new version. Im using sio2ObjectDuplicate this way

Code:

   SIO2object *_Object1 = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, ObjectName);
   SIO2object *_Object = sio2ObjectDuplicate(_Object1, dupname);
   _Object->pos->x = 0.0;
   _Object->pos->y = 0.0;
   _Object->pos->z = 0.0;   
   _Object->type = 1;

   if( sio2ObjectMapBuffer( _Object1 ) )
   {     
      
      _Object->buf = _Object1->buf;
      
      sio2PhysicAddRigidBody( sio2->_SIO2physic,
                            _Object );
      
      _Object->buf = NULL;
      
      sio2ObjectUnmapBuffer( _Object1 );
   }

   _Object->_btRigidBody->setActivationState(ACTIVE_TAG);
   sio2ObjectBindMatrix( _Object );


The first thing I noticed was that after object duplication, the type of the new object is not set so I had to set it manually to 1 as you can see If I want my object to appear on screen.

After that when I try to erase that object, I get an EXC_BAD_ACCESS error. This is the stack:

Code:

Thread 0 Crashed:
0  tutorial06_1                     0x00164bd5 btCollisionObject::getBroadphaseHandle() + 9 (btCollisionObject.h:249)
1  tutorial06_1                     0x00191771 btCollisionWorld::removeCollisionObject(btCollisionObject*) + 17 (btCollisionWorld.cpp:202)
2  tutorial06_1                     0x00232b76 btSoftRigidDynamicsWorld::removeSoftBody(btSoftBody*) + 48 (btSoftRigidDynamicsWorld.cpp:113)
3  tutorial06_1                     0x001633b8 sio2PhysicRemoveObject(SIO2physic*, SIO2object*) + 326

This is exactly in btCollisionObject::getBroadphaseHandle()
Code:

   SIMD_FORCE_INLINE btBroadphaseProxy*   getBroadphaseHandle()
   {
      return m_broadphaseHandle;
   }

In execution time Ive proved that m_broadphaseHandle is not null (at least at creation time).

Did I missed something in the object duplication code? Is this a bug? a feature?

Cheers,
Iphoniac

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Testing and failing Object duplication

Post  sio2interactive on Thu Dec 11, 2008 6:01 am

Browse on this forum I post an example on how to use sio2ObjectDuplicate...
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Testing and failing Object duplication

Post  iphoniac on Thu Dec 11, 2008 6:21 am

You mean This?

Ive used the same scheme...

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Testing and failing Object duplication

Post  iphoniac on Thu Dec 11, 2008 12:29 pm

Somebody duplicating objects can give me a clue?

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Testing and failing Object duplication

Post  matt on Thu Dec 11, 2008 1:20 pm

You're probably trying to remove the object in the collision callback which leads to problems if the object gets notified for another collision later (obj1 hits obj2 and obj2 hits obj1) in the loop. Better remember the object and remove it after the physics loop.

Best,
Matt

matt

Posts : 155
Join date : 2008-09-30

View user profile http://elfrun.net

Back to top Go down

Re: Testing and failing Object duplication

Post  iphoniac on Fri Dec 12, 2008 4:10 am

Ive found the problem. Its a bug in sio2PhysicRemoveObject:
Code:

      if( _btRigidBody == _SIO2object->_btRigidBody )
      {
         delete _btRigidBody->getCollisionShape();
         delete _btRigidBody->getMotionState();
         
         _SIO2physic->_btSoftRigidDynamicsWorld->removeRigidBody( _btRigidBody );
         _SIO2physic->_btSoftRigidDynamicsWorld->removeCollisionObject( _btCollisionObject );
         
         delete _btRigidBody;
         _btCollisionObject = _btRigidBody = NULL;
         
         break;
      }
      
      else if( _btSoftBody == _SIO2object->_btSoftBody )
      {
         _SIO2physic->_btSoftRigidDynamicsWorld->removeSoftBody( _btSoftBody );
         _SIO2physic->_btSoftRigidDynamicsWorld->removeCollisionObject( _btCollisionObject );
         
         delete _btSoftBody;
         _btCollisionObject = _btSoftBody = NULL;
         
         break;
      }

      }

If the object doesnt have _btSoftBody, both _btSoftBody and _SIO2object->_btSoftBody are NULL so the condition is true and code fails in removeSoftBody( _btSoftBody );

THe object can have rigid body or soft body, so the right code should be this
Code:

      if( _btRigidBody && (_btRigidBody == _SIO2object->_btRigidBody ))
      {
         delete _btRigidBody->getCollisionShape();
         delete _btRigidBody->getMotionState();
         
         _SIO2physic->_btSoftRigidDynamicsWorld->removeRigidBody( _btRigidBody );
         _SIO2physic->_btSoftRigidDynamicsWorld->removeCollisionObject( _btCollisionObject );
         
         delete _btRigidBody;
         _btCollisionObject = _btRigidBody = NULL;
         
         break;
      }
      else if(_btSoftBody && ( _btSoftBody == _SIO2object->_btSoftBody ))
      {
         _SIO2physic->_btSoftRigidDynamicsWorld->removeSoftBody( _btSoftBody );
         _SIO2physic->_btSoftRigidDynamicsWorld->removeCollisionObject( _btCollisionObject );
         
         delete _btSoftBody;
         _btCollisionObject = _btSoftBody = NULL;
         
         break;
      }

At least this works for me.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Testing and failing Object duplication

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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