I'm building a visualization application using SFML.Net which uses the main thread to process a GUI interface, and a separate thread for rendering. Currently the rendering thread is throwing an exception when attempting to draw a VertexArray (PrimitiveType.Quads) to a RenderTexture.
The exception is an AccessViolationException occurring in sfmlnet-graphics-2.dll, stating
Attempted to read or write protected memory. This is often an indication that other memory is corrupt
The exception occurs on a line containing the following code:
//target is a RenderTarget - the RenderTexture in this case, m_BorderVertices is the VertexArray, and states will always be
//RenderStates.Default
target.Draw(this.m_BorderVertices, states);
The RenderTexture and VertexArray are both created by the rendering thread, all other RenderTargets in the program are marked inactive during the Draw call, and the RenderTexture is marked active within the rendering thread just prior to the Draw call. I have thoroughly tested the way my shared resources are locked.
I've noticed a couple other questions floating around online regarding this error, but they haven't led me to any solutions... are there any common causes for this exception that any of you are aware of? I'm a little wary of posting code, since the source isn't exactly simple... I might be able to create an MCVE, but if this has a common cause then I'd rather not waste my time. Thanks!
EDIT using a copy of sfmlnet-graphics-2.dll compiled for debugging, I have found that the error is thrown on line 182 of VertexArray.cs:
sfRenderTexture_drawVertexArray(((RenderTexture)target).CPointer, CPointer, ref marshaledStates);