irrBullet 0.1.8 - Bullet physics wrapper

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Rocko Bonaparte
Posts: 48
Joined: Tue Aug 31, 2010 6:27 am

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by Rocko Bonaparte »

cobra wrote: Hi Rocko,

You are correct; you're making the memory leaks yourself.

Use this function to remove a collision object (both softbody and rigidbody):

Code: Select all

void irrBulletWorld::removeCollisionObject(ICollisionObject* const obj, bool deleteObject)
Never call delete on a pointer provided by irrBullet except the irrBulletWorld pointer.
Is there anything else to it? I have rerun valgrind since then, seeing that the freeing code was run, and it still purports to be leaking. The leak origin is when I allocate the RigidBody, so I believe the remove is incomplete. That being said, if I do a delete after the remove, I get a double free. So I am very perplexed. I have seen the program walk through the code that calls removeCollisionObject so I figured I was okay.
Rocko Bonaparte
Posts: 48
Joined: Tue Aug 31, 2010 6:27 am

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by Rocko Bonaparte »

I think the leaks are in the wrapper. I will soon try to add some changes into the destructor that will make them go away.

In rigidbody.cpp, a motion state is created that I don't see getting explicitly freed. Valgrind was getting caught up on that.

In the IGImpactMeshShape source file igimpactmeshshape.cpp, it's creating a btImpactMeshShape, but it doesn't appear to get freed. This is more interesting to me because I think I see sphere shapes I'm using elsewhere that don't explicitly free their underlaying stuff, yet I don't get any complaints on them. So I wonder if the free policy is different for a bullet impact mesh shape than a sphere mesh shape. The physics object that is based off of the impact mesh is getting removed, and I do see in the logging that it is considered to have been deleted.

Outside of this it looks like my bullet world object wasn't getting freed, and a whole new can of worms opened up after I deleted it in unrelated code. I have to clear that out first, then I will worry about the motion state stuff.

Cobra, I added ghost objects to your code, and if I find I've reduced some leaks, I'd like to send a patch to you. The ghost objects are particularly important to me for game logic stuff.

Edit: Deleting the motion state in the destructor did take care of the leak and it looks like nothing has yet exploded as a consequence of doing this. I think a lot of the other stuff I'm seeing is from bullet. I think it replaced malloc() with its own version, so valgrind gets completely messed up with it.
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by cobra »

Hi Rocko,

I found this leak with the motion state last week but I didn't want to report anything here until I confirmed that I didn't miss something since I haven't touched irrBullet's code in many months.

Right now I can't promise a new release or even an SVN update, but I will try my best to get on it in the future.

Thank you for your feedback and research.

- Josiah
Josiah Hartzell
Image
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by eejin »

I have trouble building the included examples. These errors occur:

-------------- Build: Win32 GCC Release in RaycastTank ---------------

mingw32-g++.exe -Wall -fexceptions -O2 -Wall -I..\..\..\include -I..\..\..\include\bheaders\Bullet -I..\..\source -I..\..\source\bheaders -I..\..\source\bheaders\Bullet -IC:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\include -IC:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\include -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source\bheaders -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source\bheaders\Bullet -c C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\examples\RaycastTank\raycasttankexample.cpp -o obj\Release\RaycastTank\raycasttankexample.o
mingw32-g++.exe -Wall -fexceptions -O2 -Wall -I..\..\..\include -I..\..\..\include\bheaders\Bullet -I..\..\source -I..\..\source\bheaders -I..\..\source\bheaders\Bullet -IC:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\include -IC:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\include -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source\bheaders -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source\bheaders\Bullet -c C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\examples\framework\exampleframework.cpp -o obj\Release\framework\exampleframework.o
mingw32-g++.exe -Wall -fexceptions -O2 -Wall -I..\..\..\include -I..\..\..\include\bheaders\Bullet -I..\..\source -I..\..\source\bheaders -I..\..\source\bheaders\Bullet -IC:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\include -IC:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\include -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source\bheaders -IC:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\source\bheaders\Bullet -c C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\examples\RaycastTank\main.cpp -o obj\Release\RaycastTank\main.o
mingw32-g++.exe -L..\..\lib\win32_gcc\ -o ..\..\bin\win32_gcc\RaycastTank.exe obj\Release\RaycastTank\raycasttankexample.o obj\Release\framework\exampleframework.o obj\Release\RaycastTank\main.o -s ..\..\lib\win32_gcc\Release\libirrBullet.a C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\lib\libIrrlicht.a -lbulletdynamics -lbulletsoftbody -lGIMPACTUtils -llinearmath -lbulletcollision C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\lib\Win32-visualstudio\Irrlicht.lib C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\lib\win32_gcc\Release\libirrBullet.a C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\lib\win32_gcc\libBulletDynamics.a C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\lib\win32_gcc\libBulletSoftBody.a C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\lib\win32_gcc\libLinearMath.a C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.71\irrBullet-0.1.71\lib\win32_gcc\libBulletCollision.a
mingw32-g++.exe: C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\lib\libIrrlicht.a: No such file or directory
Process terminated with status 1 (0 minutes, 6 seconds)
0 errors, 0 warnings

Couldn't find one libIrrlicht.a on my whole computer.

Also when I try running raycasttank(.exe) it says that it cannot load terrainMain.b3d file becouse it can't be opened. And collision can't open JagdPanther.b3d
Softbody can't open a detailmap3.png file.

Windows7 x64 Code::Blocks Mingw32
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by cobra »

eejin:

You first need to have the Irrlicht engine SDK installed, of course.

Finally, you need to tell your compiler where to find libIrrlicht.a.

The examples probably can't open their media files if you're running them from within the IDE with an improper working directory.



Moreover, I verified the motion state memory leak in 0.1.71 and fixed it (simply).

The fix has been committed to the irrBullet trunk as revision 44.

https://irrbullet.svn.sourceforge.net/s ... llet/trunk


EDIT:

I also designed a new logo for irrBullet:

Image
Last edited by cobra on Sat Nov 05, 2011 1:22 am, edited 1 time in total.
Josiah Hartzell
Image
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by eejin »

Thank you for answering but for the examples it are actually the .exe files located in the bin folder. Where should they be put then?
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by cobra »

Hi eejin,

Are they in the bin/ folder or bin/win32_gcc? They should be in the latter.

- Josiah
Josiah Hartzell
Image
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by eejin »

Mhmm I don't know what went wrong but I removed it unzipped the original one and it works now.
Thanks for youre help.
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by RdR »

To create IRigidBody for your TerrainSceneNode used a modified version from ( http://irrlicht.sourceforge.net/forum/v ... hp?t=34955 )
And added an constructor to the IBvhTriangleMeshShape class.

Code: Select all

 
//Create a collision btTriangleMesh for the terrain collision
btTriangleMesh * mTriMesh = new btTriangleMesh();
irr::scene::CDynamicMeshBuffer* buffer = 0;
btVector3 vertices[3];
s32 j, k;
buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, irr::video::EIT_32BIT);
terrainNode->getMeshBufferForLOD(*buffer, 0);
 
//Build the triangleMesh
const irr::u32 indexCount = buffer->getIndexCount();
irr::video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*) buffer->getVertexBuffer().getData();
u32* mb_indices = (u32*) buffer->getIndices();
for (j = 0; (u32) j < indexCount; j += 3) {
        for (k = 0; k < 3; k++) {
                s32 index = mb_indices[j + k];
                vertices[k] = btVector3(mb_vertices[index].Pos.X * terrainNode->getScale().X, mb_vertices[index].Pos.Y * terrainNode->getScale().Y, mb_vertices[index].Pos.Z * terrainNode->getScale().Z);
        }
        mTriMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
}
 
buffer->drop();
//Add the terrain collision shape to the world
btBvhTriangleMeshShape* mShape = new btBvhTriangleMeshShape(mTriMesh, true);
btDefaultMotionState* state = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(terrainNode->getPosition().X, terrainNode->getPosition().Y, terrainNode->getPosition().Z)));
IBvhTriangleMeshShape* shape = new IBvhTriangleMeshShape(terrainNode, mShape, 0);
IRigidBody* terrain = world->addRigidBody(shape);
terrain->getPointer()->setMotionState(state);
 
bvhtrianglemeshshape.h

Code: Select all

 
IBvhTriangleMeshShape(irr::scene::ISceneNode *n, btBvhTriangleMeshShape* bvhShape, irr::f32 m);
 
bvhtrianglemeshshape.cpp

Code: Select all

 
IBvhTriangleMeshShape::IBvhTriangleMeshShape(ISceneNode *n, btBvhTriangleMeshShape* bvhShape, f32 m)
{
    node = n;
    mass = m;
 
    type = ECST_BVHTRIMESH;
 
    shape = bvhShape;
 
    calculateLocalInertia(getMass(), vector3df(0.0f,0.0f,0.0f));
}
 
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by polylux »

Thanks! Though wouldn't it be more performant to use the btHeightfieldTerrainShape instead? I take it, this approach would be better for large terrains.
beer->setMotivationCallback(this);
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by RdR »

polylux wrote:Thanks! Though wouldn't it be more performant to use the btHeightfieldTerrainShape instead? I take it, this approach would be better for large terrains.
Why would it better perform than a triangle mesh shape?
Just wondering, because if it really is better i might consider using it in TANK@WAR as well.
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by polylux »

Oh I just assumed it'd be more suitable for large meshes, such as terrain. Then again I read here that you can throw loads of triangles into a btBvhTriangleMeshShape. What's your impression? TaW uses a quite big terrain, you don't seem to have any problems, right?
beer->setMotivationCallback(this);
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by RdR »

polylux wrote:Oh I just assumed it'd be more suitable for large meshes, such as terrain. Then again I read here that you can throw loads of triangles into a btBvhTriangleMeshShape. What's your impression? TaW uses a quite big terrain, you don't seem to have any problems, right?
Yeah, just looked at the current map (free hills) and it has ~132k triangles, and we don't have any problems using the Triangle mesh shape.
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by Cube_ »

awesomesauce.
This is what I was looking for :D
Now I won't have to figure out how to implement bullet :D
Thanks!
"this is not the bottleneck you are looking for"
baiqian
Posts: 43
Joined: Sun Apr 06, 2008 2:29 pm

Re: irrBullet 0.1.71 - Bullet physics wrapper

Post by baiqian »

hello, I try to compile irrbullet with VS2010, but I got only 1 error" cannot find include file" kinematiccharactercontroller.h". I search irrbullet directory, there is no this file. Anyone can help?
Post Reply