Bug: OgreNewt memory leak

rride

19-09-2011 11:09:10

:!:
Having 200k of objects in scene I found that every time they are recreated approximately 600 MB of memory is leaked. I dug into the source and found the following:

namespace OgreNewt
{
//...
Collision::Collision(const NewtonCollision* collision, const World* world) : m_col((NewtonCollision*)collision)
{
// collision here has refCount == 1
m_world = world;
NewtonAddCollisionReference (m_col);
// collision here has refCount == 2
}

Collision::~Collision()
{
if (m_world->getNewtonWorld() && m_col)
{
NewtonReleaseCollision( m_world->getNewtonWorld(), m_col );
// collision here has refCount == 1, nothing is detructed
}
}




so if the code is changed to

namespace OgreNewt
{
//...
Collision::Collision(const NewtonCollision* collision, const World* world) : m_col((NewtonCollision*)collision)
{
m_world = world;
// NewtonAddCollisionReference (m_col);
}

everything seems to be working perfectly