AccessViolationException after closing game

Hello. I’m new to XNA and MonoGame, but I’ve encountered some strange behavior and, after looking it up, I can’t seem to find any reason or solution for it. I’m starting out by loading a spitefont, and it’s the only thing I’m loading, from another class. It loads and I can use it. But after I close the game, it throws an AccessViolationException coming from OpenTK.Graphics.OpenGL.GL.DeleteTextures(Int32 n, Int32& textures) (I’m using the latest WindowsGL MonoGame) Besides an extra class that literally only loads this spirtefont and nothing else, I’m using a vanilla XNA template. I’m loading the spitefont exactly how all the guides say to and I don’t see anything else I’m supposed to be doing like disposing it or anything. My C# compiler is version 4.6.1055.0. Any help for this would be appreciated.

UPDATE: Switching to to the DirectX version of MonoGame fixed this issue. Is this a bug? I tried looking at the open issues and it seems a lot of people ran into it a few years ago, but nothing recent. Is this a new regression?

It’s probably the Main method in your program.cs file… The Game instance needs to be wrapped in a using statement

using (var game = new Game1()) { game.Run(); }

1 Like

That fixed it! Thank you! I should probably look into using statements some time, haha.