Mesh memory leak

Problems building or running the engine, queries about how to use features etc.
Post Reply
jhwangbo
Gnoblar
Posts: 10
Joined: Sun Feb 24, 2019 11:27 pm
x 1

Mesh memory leak

Post by jhwangbo » Fri Jul 05, 2019 10:21 am

Ogre Version: :1.11.5:
Operating System: :Ubuntu 16.04/18.04:
Render System: :opengl:

I have an application where I have to delete and recreate meshes frequently. I am using OgreAssimp to create a mesh. I also create mesh manually in a few places. The app was getting slower and slower over time. After running valgrind on a very simplified version, I noticed that there is an issue in OgreMesh.cpp. When Mesh is destructed, the destructor is called correctly (tested with a simple cout). However, Mesh::unloadImpl is not called. This causes all the sub-mesh resources to be leaked every time I destroy a mesh.

I heard v1.11.6 has many bug fixes so I want to migrate to v1.11.6. but there OgreImgui is not working properly. It complains that EndFrame() or Render() is not called.
0 x

jhwangbo
Gnoblar
Posts: 10
Joined: Sun Feb 24, 2019 11:27 pm
x 1

Re: Mesh memory leak

Post by jhwangbo » Fri Jul 05, 2019 11:56 am

update. adding unloadImpl() in the destructor directly solved the memory leaks related to OgreMesh.cpp. But this is a hack. I would like to have a proper solution...

OgreImgui works in v1.11.6 (not sure what I did last time). but the memory leak persists in v1.11.6
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 836
Joined: Sun Mar 30, 2014 2:51 pm
x 147
Contact:

Re: Mesh memory leak

Post by paroj » Fri Jul 05, 2019 5:02 pm

~Mesh() calls Resource::unload() which should call Mesh::unloadImpl(). Can you debug why this breaks?
0 x

jhwangbo
Gnoblar
Posts: 10
Joined: Sun Feb 24, 2019 11:27 pm
x 1

Re: Mesh memory leak

Post by jhwangbo » Fri Jul 05, 2019 8:22 pm

I figured out that it doesn't pass this line in Resource::unload(void) (OgreResource.cpp)

Code: Select all

if (old!=LOADSTATE_LOADED && old!=LOADSTATE_PREPARED) return;
mLoadingState is set to unloaded. So I checked its creation and found that the Mesh doesn't call Resource::load(bool background) at all. The meshes that I create manually seem fine. They call load() properly. But the ones created by OgreAssimp don't call them. I added these lines in OgreAssimp.cpp and it seems like the memory leak is gone now (apart from the stb_img issue that I am also investigating).

Code: Select all

for(auto mesh: mMeshes)
   mesh->load();
Is this a bug in OgreAssimp? Where this should be called?
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 836
Joined: Sun Mar 30, 2014 2:51 pm
x 147
Contact:

Re: Mesh memory leak

Post by paroj » Fri Jul 05, 2019 9:28 pm

yes, this is a bug in OgreAssimp. load() should be called after the mesh is loaded, see:
https://github.com/OGRECave/ogre/blob/m ... #L804-L833
0 x

Post Reply