Critter::Body destroy memory leak

saejox

10-12-2011 02:42:44

Hi,

I'm using Critter::Body as my projectiles.
i create it and destroy it as soon its done.

i destroy it like this.


Ogre::SceneNode *scenenode = theIterator->body->getNode()->getSceneNode();
mRenderSystem->destroyBody(theIterator->body);
destroySceneNode(scenenode);


separately destroying scene node since deleting body does not delete it.
there is still a memory leak. memory usage keeps increasing even though there are no projectiles in the game.
Visual leak detector gives this output:
---------- Block 27220 at 0x02601678: 32 bytes ----------
Leak Hash: 0xBD439395 Count: 36
Call Stack:
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory (43): Oyun.exe!std::_Allocate<std::_Tree_nod<std::_Tmap_traits<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,Critter::AnimationState> >,0> >::_Node> + 0xC bytes
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory (145): Oyun.exe!std::allocator<std::_Tree_nod<std::_Tmap_traits<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,Critter::AnimationState> >,0> >::_Node>::allocate + 0xB bytes
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree (1384): Oyun.exe!std::_Tree<std::_Tmap_traits<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,Critter::AnimationState> >,0> >::_Buynode + 0xD bytes
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree (1178): Oyun.exe!std::_Tree<std::_Tmap_traits<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,Critter::AnimationState> >,0> >::_Init + 0x8 bytes
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree (511): Oyun.exe!std::_Tree<std::_Tmap_traits<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,Critter::AnimationState> >,0> >::_Tree<std::_Tmap_traits<unsigned int,Critter::AnimationState,std::less<unsigned int>,st
c:\program files (x86)\microsoft visual studio 9.0\vc\include\map (104): Oyun.exe!std::map<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,Critter::AnimationState> > >::map<unsigned int,Critter::AnimationState,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,
c:\nxogre\sdk\nxogremap.h (57): Oyun.exe!NxOgre::map<unsigned int,Critter::AnimationState,NxOgre::GC::NoGarbageCollection>::map<unsigned int,Critter::AnimationState,NxOgre::GC::NoGarbageCollection> + 0x4D bytes
0x0031E440 (File and line number not available): Oyun.exe!`eh vector constructor iterator' + 0x60 bytes
c:\critter\build\source\critternode.cpp (43): Oyun.exe!Critter::Node::Node + 0x67 bytes
c:\nxogre\sdk\nxogregc.h (150): Oyun.exe!NxOgre::GC::safe_new2<Critter::Node,Ogre::SceneManager *,Critter::RenderSystem *> + 0x32 bytes
c:\critter\build\source\critterrendersystem.cpp (81): Oyun.exe!Critter::RenderSystem::createBody + 0x25 bytes
c:\users\mikbal\desktop\projects\oyun\oyun\projectilemanager.cpp (81): Oyun.exe!ProjectileManager::Routine + 0xC4 bytes
c:\users\mikbal\desktop\projects\oyun\oyun\src\oyun.cpp (1831): Oyun.exe!Oyun::frameRenderingQueued
0x625C710B (File and line number not available): OgreMain_d.dll!Ogre::PreApplyTextureAliasesScriptCompilerEvent::~PreApplyTextureAliasesScriptCompilerEvent + 0x6ADBCB bytes
0x625C74E7 (File and line number not available): OgreMain_d.dll!Ogre::PreApplyTextureAliasesScriptCompilerEvent::~PreApplyTextureAliasesScriptCompilerEvent + 0x6ADFA7 bytes
0x625CA076 (File and line number not available): OgreMain_d.dll!Ogre::PreApplyTextureAliasesScriptCompilerEvent::~PreApplyTextureAliasesScriptCompilerEvent + 0x6B0B36 bytes
0x625C7979 (File and line number not available): OgreMain_d.dll!Ogre::PreApplyTextureAliasesScriptCompilerEvent::~PreApplyTextureAliasesScriptCompilerEvent + 0x6AE439 bytes
0x625C792F (File and line number not available): OgreMain_d.dll!Ogre::PreApplyTextureAliasesScriptCompilerEvent::~PreApplyTextureAliasesScriptCompilerEvent + 0x6AE3EF bytes
c:\users\mikbal\desktop\projects\oyun\oyun\src\baseapplication.cpp (207): Oyun.exe!BaseApplication::go + 0xE bytes
c:\users\mikbal\desktop\projects\oyun\oyun\src\oyun.cpp (2331): Oyun.exe!WinMain + 0xB bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (574): Oyun.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): Oyun.exe!WinMainCRTStartup
0x76D63677 (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77449D72 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
0x77449D45 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
Data:
78 16 60 02 78 16 60 02 78 16 60 02 CD CD CD CD x.`.x.`. x.`.....
CD CD CD CD CD CD CD CD CD CD CD CD 01 01 CD CD ........ ........


i cant find what is wrong.
do you know how to properly destroy a critter::body? am i missing something?

Yati

21-12-2011 08:47:53

Maybe you need to manually delete the Ogre::Entity as well? I don't really understand the visual leak detector output >_<

saejox

21-12-2011 15:27:02

Maybe you need to manually delete the Ogre::Entity as well? I don't really understand the visual leak detector output >_<

destroying entity like this has no effect. destroybody deletes entity if any exists.

mSceneMgr->destroyEntity(theIterator->body->getNode()->getEntityAt(0));
mRenderSystem->destroyBody(theIterator->body);


here is an interesting fact,
memory leak occurs only in debug mode. vld doesnt work in release mode, so i check it using a memory monitor. leak does not exist in release mode when i just call destroyBody (with modified critter ofcourse).

i m ignoring the memory leak for now.

betajaen

22-12-2011 21:08:15

Even if Critter didn't destroy the SceneNode and/or Entity. It would be cleaned up by Ogre once the SceneManager has been destroyed.