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.
Mesh memory leak
-
- Gnoblar
- Posts: 12
- Joined: Sun Feb 24, 2019 11:27 pm
- x 1
Re: Mesh memory leak
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
OgreImgui works in v1.11.6 (not sure what I did last time). but the memory leak persists in v1.11.6
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Mesh memory leak
~Mesh() calls Resource::unload() which should call Mesh::unloadImpl(). Can you debug why this breaks?
-
- Gnoblar
- Posts: 12
- Joined: Sun Feb 24, 2019 11:27 pm
- x 1
Re: Mesh memory leak
I figured out that it doesn't pass this line in Resource::unload(void) (OgreResource.cpp)
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).
Is this a bug in OgreAssimp? Where this should be called?
Code: Select all
if (old!=LOADSTATE_LOADED && old!=LOADSTATE_PREPARED) return;
Code: Select all
for(auto mesh: mMeshes)
mesh->load();
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Mesh memory leak
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
https://github.com/OGRECave/ogre/blob/m ... #L804-L833