MOgre crashes randomly

durium

23-02-2013 10:51:03

Hello world !

I seem to have a problem with my Mogre installation, it crashes randomly !
I get this log each time :
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at Ogre.GpuProgramParameters.{dtor}(GpuProgramParameters* )
at Ogre.GpuProgramParameters.__delDtor(GpuProgramParameters* , UInt32 )
at Ogre.SharedPtr<Ogre::GpuProgramParameters>.{dtor}(SharedPtr<Ogre::GpuProgr
amParameters>* )
at Ogre.SharedPtr<Ogre::GpuProgramParameters>.__vecDelDtor(SharedPtr<Ogre::Gp
uProgramParameters>* , UInt32 )
at Mogre.GpuProgramParametersSharedPtr.!GpuProgramParametersSharedPtr()
at Mogre.GpuProgramParametersSharedPtr.Dispose(Boolean )
at Mogre.GpuProgramParametersSharedPtr.Finalize()

It also seem that using a vertex buffer seem to cause the crash to occur more often...
Here is how i use my HardwareVertexBufferSharedPtr :

private unsafe void removeFace(int pos) {
RenderOperation moData = new RenderOperation();
this.block.GetSection(0).GetRenderOperation(moData);

VertexElement posEl = moData.vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.VES_POSITION);
HardwareVertexBufferSharedPtr vBuff = moData.vertexData.vertexBufferBinding.GetBuffer(posEl.Source);

uint size = VertexElement.GetTypeSize(VertexElementType.VET_FLOAT3);

byte* pVertex = (byte*)vBuff.Lock(HardwareBuffer.LockOptions.HBL_NORMAL) + vBuff.VertexSize * pos;
float* pReal;

for(int i = 0; i < 4; i++) {
posEl.BaseVertexPointerToElement(pVertex, &pReal);

pReal[0] = 0; pReal[1] = 0; pReal[2] = 0;
pVertex += vBuff.VertexSize;
}

vBuff.Unlock();
vBuff.Dispose();
}


How can i solve this issue ? Thanks !

durium

02-03-2013 11:24:01

I need some help please !

BrainScan

19-03-2013 01:32:56

This type of error generally happens when the .NET garbage collector tries to clean up an object that has already been cleaned up by OGRE automatically. I find that it happens most often with code that runs every frame and gets a new instance of an OGRE object that derives from SharedPtr (in MOGRE that should be anything that ends in Ptr).

I've been dealing with it in two different ways.

1) Get the object once and store a reference to it, reusing it every frame. You have to make sure to call Dispose() on that reference before OGRE cleans it up automatically though.

2) Surround the usage of the pointer with a using statement to ensure it gets Disposed immediately after you're finished with it. This is probably the safer route.

using (GpuProgramParametersSharedPtr parameters = pass.GetFragmentProgramParameters())
{
//do something
}


What it comes down to is being careful about managing and releasing resources which is generally unintuitive when programming in .NET.

durium

23-03-2013 19:33:41

thank you !

That really helped !
So I'm actually using a mix of the 2 solutions.
I was using a HardwareVertexBufferSharedPtr.