Potential Heap Corruption on misuse


13-09-2013 22:23:37

I got a minor problem when closing the window of my application through the close button (never any other way, like triggering the end of the app using keyboard keys).
After some time hunting it, I found that a snippet of code using OgreProcedural was part of the source of the problem. That code was creating a temporary mesh. However, it was called once for each instance, and there is thousands of instances.
Anyway, refactoring this code fixed the issue, but I'm not sure of the exact source, is it something OgreProcedural does (a memory leak? a pointer that is used when it shouldn't? heap corruption is rather strange!) and I posted all the details I've got so far there: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=78894

I don't have time to hunt it more so I'll let you see if it's worth pursuing.


30-09-2013 10:47:43

Forum post notification seems to have been broken for the last month, so I'm just discovering it right now...

Is the window the main application window, thus triggering a 'delete root' ?
Is there anything in the Ogre.log?
When OgreProcedural creates a mesh, it first creates a manualObject, fills it and use its utility function convertToMesh().
The manualObject is then deleted.
The temporary TriangleBuffer is stack allocated, so it's destroyed on the fly.

So it's the exact same case as if you would create a mesh using ManualObject by yourself.
The difference with loading an Ogre Mesh is that it's flagged as manually loaded, and thus not reloadable.
For example, if you use a background resource queue, ResourceBackgroundQueue::unloadResourceGroup only unloads non-manually-loaded resources.
I'm not saying it's the cause of your issue, since I've been unable to reproduce it, but maybe there's something connected to that.


30-09-2013 11:00:27

I'm starting to believe the issue is from my own code but it's really hard to figure out. For example currently I can see the same issue only sometime, while the fix of not re-creating a lot of generators did minimize the issue to only a few cases.
Also I didn't check completely the Ogre log because the error is visible only when debugging (with VS). I'll try to gather more information soon.