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
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!
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.
The C++ code for DestroyHardwareBuffer is
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).
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
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.
Can you post an example that uses Ogre2DManager.cs and crashes with
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.
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
Ah, I understand now. Once again, thanks for the help!
Thank you for porting it to Ogre! I guess that should be posted somewhere in the MOGRE wiki.
All right, where is the fully working one so I can put it in the wiki?