leak of memory

View previous topic View next topic Go down

leak of memory

Post  hazeleye on Wed Nov 26, 2008 3:14 am

Hi
I have two scenes (two .sio2 files). First scene playing when program started, when I touching (for example) this scene will be unload and next scene will be loaded and played
It's my loading function:
Code:

{   
   sio2ResourceUnloadAll(sio2->_SIO2resource);
   sio2->_SIO2resource->uf = 0;
   
   if( !sio2->_SIO2resource->n_entry )
   { sio2ResourceCreateDictionary( sio2->_SIO2resource ); }
   
   if( !sio2->_SIO2resource->uf )
   {
      sio2ResourceOpen( sio2->_SIO2resource,
                   _levelParameters.fileName, 1);
   }
      
   unsigned int i = 0;
   while (i != sio2->_SIO2resource->gi.number_entry )
   {
      sio2ResourceExtract( sio2->_SIO2resource );
      ++i;
   }
   sio2ResourceClose( sio2->_SIO2resource );
   
   sio2ResourceBindAllImages( sio2->_SIO2resource );
   sio2ResourceBindAllMaterials( sio2->_SIO2resource );
   sio2ResourceBindAllInstances( sio2->_SIO2resource );
   sio2ResourceBindAllMatrix( sio2->_SIO2resource );
   sio2ResourceBindAllPhysicObjects( sio2->_SIO2resource, sio2->_SIO2physic );
   
   sio2ResourceGenId( sio2->_SIO2resource );
   
   sio2ResourceResetState();

        ...
}

But when it's function run second time a have leak of memory in function sio2ResourceBindAllPhysicObjects
I think , that it have place because in function sio2PhysicAddRigidBody after _btCollisionShape = new btBvhTriangleMeshShape( _btTriangleMesh, 1 ); must be: delete _btTriangleMesh;

But if I write it, I have "EXC_BAD_SIGNAL" after some iterations

Can you help me?

PS: rename function sio2PhysicRemoveAllObjetcs to sio2PhysicRemoveAllObjects Wink

hazeleye

Posts : 34
Join date : 2008-09-24

View user profile

Back to top Go down

Re: leak of memory

Post  sio2interactive on Wed Nov 26, 2008 3:57 am

Try this one lemme know if you still have the same problem...

Code:


void sio2PhysicRemoveAllObjects( SIO2physic *_SIO2physic )
{
   while( _SIO2physic->_btSoftRigidDynamicsWorld->getNumCollisionObjects() )
   {
      btCollisionObject *_btCollisionObject = _SIO2physic->_btSoftRigidDynamicsWorld->getCollisionObjectArray()[ 0 ];
      
      btRigidBody *_btRigidBody = btRigidBody::upcast( _btCollisionObject );

      if( _btRigidBody )
      {
         delete _btRigidBody->getCollisionShape();
         delete _btRigidBody->getMotionState();
         
         _SIO2physic->_btSoftRigidDynamicsWorld->removeRigidBody( _btRigidBody );
         _SIO2physic->_btSoftRigidDynamicsWorld->removeCollisionObject( _btCollisionObject );
         
         delete _btRigidBody;
         _btCollisionObject = _btRigidBody = NULL;
      }
      else
      {
         btSoftBody *_btSoftBody = btSoftBody::upcast( _btCollisionObject );
         
         _SIO2physic->_btSoftRigidDynamicsWorld->removeSoftBody( _btSoftBody );
         _SIO2physic->_btSoftRigidDynamicsWorld->removeCollisionObject( _btCollisionObject );
         
         delete _btSoftBody;
         _btCollisionObject = _btSoftBody = NULL;
      }
   }
   

   while( _SIO2physic->_btSoftRigidDynamicsWorld->getNumConstraints() )
   {
      btTypedConstraint *_btTypedConstraint = _SIO2physic->_btSoftRigidDynamicsWorld->getConstraint( 0 );
      
      _SIO2physic->_btSoftRigidDynamicsWorld->removeConstraint( _btTypedConstraint );
      
      delete _btTypedConstraint;
      _btTypedConstraint = NULL;
   }
}

avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: leak of memory

Post  hazeleye on Wed Nov 26, 2008 4:13 am

It's not help me .... Crying or Very sad

hazeleye

Posts : 34
Join date : 2008-09-24

View user profile

Back to top Go down

Re: leak of memory

Post  sio2interactive on Wed Nov 26, 2008 4:02 pm

Checking your code again... I can see that after unloading everything you are not recreating a new physic world... before using sio2ResourceBindAllPhysicObjects, so where sio2->_SIO2physic is pointing to since you get rid of it with sio2ResourceUnloadAll(sio2->_SIO2resource);
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: leak of memory

Post  hazeleye on Wed Nov 26, 2008 10:41 pm

I change your tutorial04 and have this leak again
Functions, wich was change:
Code:

http://template.mm
void templateLoading( void )
{
   sio2ResourceUnloadAll(sio2->_SIO2resource);
   
   //loading physic
   vec3 gravity;
   gravity.x =  0.0f;
   gravity.y =  0.0f;
   gravity.z = -10.0f;   
   sio2->_SIO2physic = sio2PhysicInit( "earth" );
   sio2PhysicSetGravity( sio2->_SIO2physic, &gravity );   
   sio2PhysicStop(sio2->_SIO2physic);
   
   unsigned int i = 0;   
   sio2ResourceCreateDictionary( sio2->_SIO2resource );
   sio2ResourceOpen( sio2->_SIO2resource,
                 "tutorial06.sio2", 1 );   
   while( i != sio2->_SIO2resource->gi.number_entry )
   {
      sio2ResourceExtract( sio2->_SIO2resource );
      ++i;
   }

   sio2ResourceClose( sio2->_SIO2resource );
   sio2ResourceResetState();
   sio2ResourceBindAllImages( sio2->_SIO2resource );
   sio2ResourceBindAllMaterials( sio2->_SIO2resource );
   sio2ResourceBindAllMatrix( sio2->_SIO2resource );
   sio2ResourceBindAllPhysicObjects( sio2->_SIO2resource, sio2->_SIO2physic );
   sio2ResourceGenId( sio2->_SIO2resource );   

   sio2PhysicPlay(sio2->_SIO2physic);
   sio2->_SIO2window->_SIO2windowrender = templateRender;
}

void templateScreenTap( unsigned char _state, int _tap, float _x, float _y )
{
   if( _state == SIO2_WINDOW_TAP_DOWN )
   {
      sio2->_SIO2window->_SIO2windowrender = templateLoading;
      glClear( GL_DEPTH_BUFFER_BIT| GL_COLOR_BUFFER_BIT);
   }
}

void templateRender( void )
{

   glMatrixMode( GL_MODELVIEW );
   glLoadIdentity();

   glClear( GL_DEPTH_BUFFER_BIT ); //  | GL_COLOR_BUFFER_BIT

   if( !sio2->_SIO2camera )
   {
      SIO2camera *_SIO2camera = ( SIO2camera * )sio2ResourceGet( sio2->_SIO2resource,
                                                  SIO2_CAMERA,
                                                  "camera/Camera" );
      if( !_SIO2camera )
      { return; }
   
      sio2->_SIO2camera = _SIO2camera;
      sio2CameraSetPerspective( _SIO2camera, sio2->_SIO2window );
   }


   sio2WindowEnterLandscape3D();
   {
      
      sio2CameraRender( sio2->_SIO2camera );
      sio2CameraUpdateFrustum( sio2->_SIO2camera );
      
      sio2ResourceCull( sio2->_SIO2resource,
                    sio2->_SIO2camera );
      
      sio2ResourceRender( sio2->_SIO2resource,
                     sio2->_SIO2window,
                     sio2->_SIO2camera );
   }
   sio2WindowLeaveLandscape3D();
}

http://EAGLView.mm
- (BOOL)createFramebuffer {
   
   glGenFramebuffersOES(1, &viewFramebuffer);
   glGenRenderbuffersOES(1, &viewRenderbuffer);
   
   glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
   glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
   glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
   
   glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
   glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
   
   glGenRenderbuffersOES(1, &depthRenderbuffer);
   glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
   glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
   glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);

   if( !sio2 )
   {
      sio2Init( &tmp_argc, tmp_argv );
      
      sio2InitGL();
      
      sio2InitAL();
      
      vec3 gravity;
      gravity.x =  0.0f;
      gravity.y =  0.0f;
      gravity.z = -10.0f;   
      sio2->_SIO2physic = sio2PhysicInit( "earth" );
      sio2PhysicSetGravity( sio2->_SIO2physic, &gravity );   
      sio2PhysicStop(sio2->_SIO2physic);
   
      sio2WindowUpdate( sio2->_SIO2window, backingWidth, backingHeight );
      
      sio2->_SIO2window->_SIO2windowrender = templateLoading;   
      
      sio2WindowShutdown( sio2->_SIO2window, templateShutdown );
      
      sio2->_SIO2window->_SIO2windowtap         = templateScreenTap;
      sio2->_SIO2window->_SIO2windowtouchmove      = templateScreenTouchMove;
      sio2->_SIO2window->_SIO2windowaccelerometer = templateScreenAccelerometer;
   }   
   return YES;
}

- (void)drawView {


   if( sio2->_SIO2window->_SIO2windowrender )
   {
      if (sio2->_SIO2physic->state == SIO2_PHYSIC_PLAY)
      {
         sio2PhysicRender( sio2->_SIO2physic,
                      sio2->_SIO2window );
      }
      
      sio2->_SIO2window->_SIO2windowrender();
      
      sio2WindowSwapBuffers( sio2->_SIO2window );
   }
   
   glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
Use "tutorial06.sio2" file

hazeleye

Posts : 34
Join date : 2008-09-24

View user profile

Back to top Go down

Re: leak of memory

Post  sio2interactive on Wed Nov 26, 2008 11:18 pm

You can use instruments to detect where the problem come from... In any case I will add that to my TODO list and come back to you ASAP.

Cheers,
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: leak of memory

Post  hazeleye on Fri Nov 28, 2008 12:01 am

if you solve this problem, please say me about that

hazeleye

Posts : 34
Join date : 2008-09-24

View user profile

Back to top Go down

Re: leak of memory

Post  sio2interactive on Wed Dec 03, 2008 1:52 am

Dude I check it out... Im using this code:

Code:


void templateLoading( void )
{
   unsigned int i = 0;
   
   vec3 gravity;
   
   gravity.x =  0.0f;
   gravity.y =  0.0f;
   gravity.z = -10.0f;   

   // Create a resource manager for the upcoming
   // resources... in other word a new "Scene" and
   // bind it to the main sio2->_SIO2resource handle.
   sio2->_SIO2resource = sio2ResourceInit();

   // Initialize a physic world and attach it
   // to the SIO2 global structure.
   sio2->_SIO2physic = sio2PhysicInit( "earth" );

   // Set the gravity of the physic world, to
   // something similar as earth. Please take note
   // that the default up vector of SIO2 is the positive
   // Z axis. So gravity should go down on the negative
   // Z axis.
   sio2PhysicSetGravity( sio2->_SIO2physic, &gravity );
   
   sio2ResourceCreateDictionary( sio2->_SIO2resource );
   
   sio2ResourceOpen( sio2->_SIO2resource,
                 "Scene.sio2", 1 );
                 //"tutorial04.sio2", 1 );
   
   /*
      Please take note that the following block
      can be customized in order to (eg:) avoid
      loading a specific type of resource or?
      
      Check out the custom loading tutorial in order
      to have idea on how to expand the capabilities
      and functionalities of the SIO2 archive loading
      mechanism.
   */
   while( i != sio2->_SIO2resource->gi.number_entry )
   {
      sio2ResourceExtract( sio2->_SIO2resource );
      ++i;
   }

   sio2ResourceClose( sio2->_SIO2resource );

   /*
      v1.2: In order to optimize the machine state
      SIO2 remember that last object, vertexgroup, material
      camera, blending mode etc... used by the last frame
      this function will reset the pointers hold in memory.
      
      Theses pointers are also use as "global" variable by
      the parser that points to the current resource SIO2
      is working with.
   */
   sio2ResourceResetState();

   sio2ResourceBindAllImages( sio2->_SIO2resource );

   sio2ResourceBindAllMaterials( sio2->_SIO2resource );

   sio2ResourceBindAllInstances( sio2->_SIO2resource );

   sio2ResourceBindAllMatrix( sio2->_SIO2resource );
   
   sio2ResourceBindAllIpos( sio2->_SIO2resource );

   sio2ResourceBindAllPhysicObjects( sio2->_SIO2resource,
                             sio2->_SIO2physic );

   sio2ResourceGenId( sio2->_SIO2resource );

   //sio2->_SIO2window->_SIO2windowrender = templateRender;
   

sio2ResourceUnloadAll( sio2->_SIO2resource );
sio2->_SIO2resource = sio2ResourceFree( sio2->_SIO2resource );
   
   
   // Force a memory leak check...
   #ifdef SIO2_DEBUG_MEM
   
      sio2MemoryReportLeaks();
   #endif
   
   //sio2PhysicPlay( sio2->_SIO2physic );
   
   //sio2->_SIO2window->fps = 30.0f;

   //_SIO2object = sio2ResourceGetObject( sio2->_SIO2resource,
   //                            "object/Cube" );
   //sio2IpoPlay( _SIO2object->_SIO2ipo );
   
   // Make sure we got a clean buffer
   glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );   
}




Working fine, no crash and no leaks...
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: leak of memory

Post  hazeleye on Thu Dec 04, 2008 1:03 am

But I have ...
I open tutorial04 in last revision of sio2_SDK , and change templateLoading() as you say. But still have this leak of memory....

[img][/img]

And I comment sio2ResourceBindAllIpos( sio2->_SIO2resource ); - SDK not contain this function...

hazeleye

Posts : 34
Join date : 2008-09-24

View user profile

Back to top Go down

Re: leak of memory

Post  sio2interactive on Thu Dec 04, 2008 4:35 am

Ahhhhhhhh yeah that one! Yeah that was a nasty one... The way I fix it (which is quite dirty) is I assign a btTriangleMesh pointer in the SIO2object structure, and use it when static triangle mesh is initialized, on sio2ObjectFree if the pointer have been assigned delete & reset it to NULL...

If someone know a better way please do tell... I even tried to upcast the collision shape in order to delete that pointer but without sucess so I stick it into the SIO2object structure... Im not sure if its intentional from Bullet or it is a leak...

Cheers,
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: leak of memory

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