Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jun 04, 2012 11:57 pm 
Offline

Joined: Mon Jun 04, 2012 11:40 pm
Posts: 14
Hi all!

I'm experimenting with Bullet physics, using Ogre as the graphics engine, and BtOgre as a wrapper. Everything works fine, except that there are some strange memory leaks. With the help of a leak detector, I've found out that the problem is related to TriangleMeshShape. Doing a google search returned this thread, and the sollution described there fixed the problem for me.

I had to modify the originally empty destructor in btTriangleMeshShape.cpp to this:
Code:
btTriangleMeshShape::~btTriangleMeshShape()
{
   delete m_meshInterface;
}


But I gues this isn't supposed to be done this way, otherwise it would have been already added to the original code. So my question is, what is the correct way to do this? And how is this done in the Bullet demos? I did a search through all of the demo code, and there are a few TriangleMeshShapes created, but I found no clean-up procedure for them, and yet there are no memory leaks in any of them.

Thanks in advance.


Top
 Profile  
 
PostPosted: Thu Jun 07, 2012 6:29 pm 
Offline

Joined: Wed Apr 28, 2010 3:09 pm
Posts: 11
I have noticed the same problem -- when creating a btTriangleMeshShape, you pass in a pointer to a btStridingMeshInterface. The btStridingMeshInterface is not copied so, if you had to dynamically create it, you need to know when the btTriangleMeshShape is deleted to be able to also free the btStridingMeshInterface.

On the other had, if the passed in btStridingMeshInterface was a local structure (say, defined locally in the enclosing application class) you can't just free it as you suggest.

The demos get around this freeing problem by not even using a btTriangleMeshShape.

I have "solved" this problem by remembering the pointer to the btStridingMeshInterface that I created and when I destroy the btTriangleMeshShape I also destroy the striding mesh. Not pretty.


Top
 Profile  
 
PostPosted: Wed Jul 18, 2012 8:30 am 
Offline

Joined: Wed Jul 18, 2012 4:54 am
Posts: 7
I think it's the way how Bullet manages the user newed memory, it chooses flexibility instead of simplicity.

In btBulletWorldImporter, it uses basically the solution that Misterblue uses, store all mesh interface in m_allocatedTriangleIndexArrays, to ensure no memory leaks when clean up.

My solution to this is just to derive from btTriangleMeshShape, named 'MyTriangleMeshShape' for example, and in its destructor, I make sure to delete m_meshInterface myself. I hate also to modify the original bullet file. Thanks to polymorphism in C++.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], kolarz3 and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group