Closed hellbender3069 closed 4 years ago
I also have a stacktrace
at OpenGL.Gl.DeleteVertexArrays(Int32 n, UInt32[] arrays) in D:\DeTweeSnoeken\OpenGL4CSharp\opengl4csharp-master\OpenGL\Core\Gl.cs:line 3372 at OpenGL.Gl.DeleteVertexArray(UInt32 vao) in D:\DeTweeSnoeken\OpenGL4CSharp\opengl4csharp-master\OpenGL\Core\GlMethods.cs:line 262 at OpenGL.GenericVAO.Dispose(Boolean disposing) in D:\DeTweeSnoeken\OpenGL4CSharp\opengl4csharp-master\OpenGL\Constructs\VAO.cs:line 680 at OpenGL.VAO.Finalize() in D:\DeTweeSnoeken\OpenGL4CSharp\opengl4csharp-master\OpenGL\Constructs\VAO.cs:line 792
The ID of the VAO that was passed was 1 so the arrays parameter contains {1}
Oof, I apologize for not responding for three years. I don't think I ever fixed it when I used it a long time ago, I ended up just writing my own OpenGL bindings, but if I get some time to look at it again soon I will update you on if I figure it out.
With OpengGl, only one thread at a time can execute Gl commands. By default that means only the main thread(the thread that runs your Main
function in this case) can execute Gl commads. If you don't dispose of a VBO
, VAO
or one of the other constructs from this library, then the garbage collector will do it for you. Problem is that the garbage collector runs on a separate thread i.e. not on the main thread.
To be more specific, the garbage collector sees that you have no more references to, for example, a VBO
so it executes its destructor. The destructor calls the dispose method which tries to destroy the buffer. The garbage collector thread isn't allowed to do that so it throws an exception.
@hellbender3069 You can fix your issue by modifying the bottom part of your Main
method to something like this.
// create a cube
cube = OpenGL.Geometry.CreateCube(program, new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
cube.DisposeChildren = true;
cube.DisposeElementArray = true;
}
while (OpenGL.Platform.Window.Open)
{
OpenGL.Platform.Window.HandleEvents();
OnRenderFrame();
}
cube.Dispose();
Tldr: You have to dispose of everything manually and if you don't then you get that exception.
Yes, exactly what @TheAIBot said above ^ You have to dispose of those objects before the program ends. Any textures, VBOs, shader programs, etc should all be cleaned up before your program exits. Hopefully this helps!
Hello TheAIBot, thank you for your comment. I noticed that I still got the exception after i added the cube.Dispose(), but your last remark en figured I also still have a program object. I also disposed of that after the cube and everything worked as expected.
Thank you very much for the help.
P.S. @giawa I got here because I followed the code in the README.md. Maybe it is an idea to add a remark about disposing the cube and program in the README.md so people who start there will have a working example?
Hello Giawa, I seem to have run into the same problem as issue #13 using Visual Studio 2019 and the example code in a console application. It happens when the application is closed and i am not sure but when I try to step into the Delegates.glDeleteVertexArray(n, arrays) function I get the System.AccessViolationException. Since Delegates is a class of internal delegates I have no idea where they are pointing to. Since jchand99 has not published any solution I am a bit in the dark here about what is happening.
Could you please be of any assistance?
With regards, Michel
Program.txt
P.S. it seems to start acting up when I add the line for the new ShaderProgram. If I don't attach those and not paint the cube nothing is wrong. If I add the line for the ShaderProgram it gives this exception. I don't need to draw the cube to trigger it.
P.P.S. sorry for also adding this to the old issue, as I later realised it isn't proper practice to revive old issues.