If I write the following code
RenderWindow window = new RenderWindow(new VideoMode(400, 300), "TGUI.Net test");
Gui gui = new Gui(window);
Picture picture = new Picture("background.jpg");
gui.Add(picture);
// ... gui.Add various test elements ...
Vertex[] test = {
new Vertex(new Vector2f(), Color.White),
new Vertex(new Vector2f(400, 0), Color.Magenta),
new Vertex(new Vector2f(400, 75), Color.Cyan),
new Vertex(new Vector2f(0, 75), Color.Yellow)
};
while (window.IsOpen) {
window.DispatchEvents();
window.Clear();
window.Draw(test, PrimitiveType.Quads);
gui.Draw(); // crash, Exception Unhandled
window.Display();
}
I get a System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
But if I comment out gui.Add(picture)
it works fine and all other tgui elements and my sfml primitives draw correctly....
Alternatively if I comment out window.Draw(test, PrimitiveType.Quads);
it works as well
Or if I change the order gui.Draw();
window.Draw(test, PrimitiveType.Quads);
it works but of course my "game content" draws on top of my gui
I also notice that standard builtin sfml types work, such as Sprite. It seems the problem arises only when used in conjunction with this window.Draw(Vertex[], PrimitiveType) signature, but I also tried abstracting this into a class that can be called with window.Draw(instance)class MyTestDrawable : Transformable, Drawable {
private Vertex[] _Vertices;
public MyTestDrawable() {
_Vertices = new Vertex[] {
new Vertex(new Vector2f(), Color.White),
new Vertex(new Vector2f(400, 0), Color.Magenta),
new Vertex(new Vector2f(400, 75), Color.Cyan),
new Vertex(new Vector2f(0, 75), Color.Yellow)
};
}
public void Draw(RenderTarget target, RenderStates states) {
states.Transform *= Transform;
target.Draw(_Vertices, PrimitiveType.Quads, states);
}
}
to no avail
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Further testing has revealed that if I first draw a standard sfml type like Sprite, I can then draw with (Vertex[], PrimitiveType) window.Draw(spriteInstance);
window.Draw(test, PrimitiveType.Quads);
gui.Draw();
with no errors.