Problems Porting Water Simulation to MOGRE

El_Zorro

17-05-2008 21:23:37

Hi I'm new to the forum, recently i began porting some of the samples not yet ported to .NET to test MOGRE Wrapper.
I began with Water Simulation because someone requested it in another topic, but I encountered some wierd errors.

The errors in question are:
  1. When iterating the particles in a ParticleSystem using the ParticleIterator (obtained with _getIterator()) I get an Invalid Access To Memory Location and a window requesting to select a debugger for the application pops up, the code is:
    ParticleIterator pit = particleSystem._getIterator();
    while (!pit.End()) // Invalid Access to memory here!!
    { ... }

    I replaced this code iterating the ParticleSystem with NumParticles and GetParticle, but it would be good to check why it is throwing this.
    [/*:m]
  2. If I press space bar to make rain, I get the circles on the water, but at some point passing the 270th circle or more I get an Ogre Exception with the message "OGRE EXCEPTION(3:RenderingAPIException): Error Presenting surfaces in D3D9RenderWindow::swapBuffers at ..\src\OgreD3D9RenderWindow.cpp (line 756)".
    This exception also appeared some times when changing the simulation parameters. But the behaviour is totally random, I couldn't find the reason for this.
    [/*:m]
  3. Last, but most annoying, when I close the application I always get the exception AccessViolationException. The stack trace is
    at Mogre.HardwareVertexBufferSharedPtr.!HardwareVertexBufferSharedPtr()
    at Mogre.HardwareVertexBufferSharedPtr.Dispose(Boolean )
    at Mogre.HardwareVertexBufferSharedPtr.Finalize()

    But I also catched it once in the same methods for a MeshPtr.
    I think that Ogre deletes the memory and then MOGRE tries to release the same memory, but I'm not sure. Because this only happens when clossing the app, and with Ptr objects stored as instance variables.
    This example code reproduces the error:
    class MainApp : Mogre.Demo.ExampleApplication.Example
    {
    private HardwareVertexBufferSharedPtr testBuffer;

    public override void CreateScene()
    {
    HardwareBufferManager bufMng = HardwareBufferManager.Singleton;
    testBuffer = bufMng.CreateVertexBuffer(
    2 * sizeof(float), 9,
    HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY);
    }
    }

    If I declare the variable inside the method I don't get the exception. I think that if the garbage collector collects the Ptr object, before Ogre is terminated, the Ptr is released correctly.[/*:m][/list:o]
    If someone with more experience in MOGRE has suggestions or knows how to fix this errors i would be grateful. I don't have a place to upload the code but if someone needs it I could send it by mail or something.
    Sorry for my bad english. :?

El_Zorro

29-05-2008 18:37:54

I've made some more testing and fixed the third error.

Just calling the Dispose() method on all HardwareVertexBufferSharedPtr before the call to root.Dispose() solved this problem.

I made an override of DestroyScene() and disposed all objects there.

Hope it helps anyone.