Ported SpriteManager2D to Mogre, getting memory leaks


25-11-2006 19:24:44


Started fiddling with Ogre/Mogre the other day, and decided to try to port the SpriteManager2D (http://www.ogre3d.org/wiki/index.php/SpriteManager2d) to Mogre. It works, after a fashion. Problem is I am getting a memory leak every time the buffer is recreated.

083196 0x0919C680 0x00000038 0x0919C670 0x00000058 0x00000000 new N N MogreVertexIndexData.cpp(68) Mogre::VertexData::VertexData

I've tried nulling/Disposing/Destroying everything I can think of, but there must be some proper way to remove the VertexData from the RenderOperation, which I assume is causing the problem. It's fair to say I could be using Mogre in the wrong way. Only used it since last night after all :roll:

For the record, I can use Windows Task Manager to confirm the leak by recreating the buffer in every frame. Code is here


Maybe I should avoid recreating the VertexData everytime I recreate the hardware buffer?

All help is greatly appreciated!


25-11-2006 19:42:22

Update: I just discovered I am only getting the leak if I attach a viewport to the scene manager handling the sprite rendering.

SceneManager mgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
Camera cam = mgr.CreateCamera("Camera");

The scene manager mgr is the very same scene manager I send to Ogre2DManager.Init(). So.. I guess I should use one scene manager for meshes and so on, and another scene manager for the sprite part?

What I don't get is how this can happen.


26-11-2006 01:36:53

The C++ code for DestroyHardwareBuffer is
delete renderOp.vertexData;
so why are you doing this

and not this ?

Also keep in mind that the equivelant of std::list is LinkedList<T> (List<T> is for std::vector).


26-11-2006 09:25:48

I was doing


but it did not help. In fact, the program would crash on that line. But it would only crash if there was a viewport connected to the scene manager. If I don't create the viewport, I get no crash, and no memory leaks.

The calls to DestroyVertex...() were made out of desperation. Don't assume I know what I'm doing here :wink:

If I were to only display sprites with Ogre2DManager, no meshes whatsoever, I wouldn't need a viewport, right? On the other hand, I can't render two different scene managers at the same time, right? So if I wanted to display both sprites and meshes at the same time, I would have to use the same scene manager.... right?

Maybe these last questions are more suited for the regular forums. :?


26-11-2006 09:45:31

Can you post an example that uses Ogre2DManager.cs and crashes with


26-11-2006 13:45:01

Certainly. I made a zip of the all the files that I thought was relevant. Grab it at


Ogre.log is also included.


26-11-2006 19:09:17

I've found what's the deal with the memory leak. The proper way is to just do
but you may or may not get a memory leak because of a GC thing. I won't get into details but if you keep references to your VertexData objects until you destroy them, you'll see that the memory leaks will be gone.
I'll fix it soon.


27-11-2006 07:31:16

I'll fix it soon.

Do you mean this will require a fix in Mogre, or that you will fix the code I posted? Either way, thanks for the help :D


27-11-2006 10:22:07

I explain the issue here.


27-11-2006 12:22:23

Ah, I understand now. Once again, thanks for the help!


27-11-2006 22:18:23


Thank you for porting it to Ogre! I guess that should be posted somewhere in the MOGRE wiki.



28-11-2006 07:35:40

My pleasue :wink:


30-11-2006 01:55:33

All right, where is the fully working one so I can put it in the wiki? :D