Hi there,
I often run into CallbackOnCollectedDelegate exceptions that are bound to GL entry point delegates calls.
As far as I know, this exception happens if a delegate is called while it has been collected by the garbage collector. Could it be an issue with LoadEntryPoint<T>()?
It doesn't seem to happen anymore if I rollback to before LoadEntryPoint used generics. But it could very well be something else since it's months old.
When it happens, it happens always during the first frame rendering. Once it rendered, if no exception has been thrown, the program works without any further exception.
It happens only while debugging from Visual Studio.
It's random, and I can't reproduce it consistently on all computers. It happens on a Surface Pro 4 (Win10, Intel GPU), on another desktop (Win8.1, NVidia GPU), but not on another one (Win8.1, ATI GPU).
It affects all our projects.
What piece of code in your project seems to cause the issue? I can try reproducing it on my Windows 10 Nvidia laptop.
An empty project with just a SpriteBatch Being/Draw/End can expose the problem. It's typically triggered upon the End call, within GetShaderHandle(), when the basic effect is being set for the first time.
I've been on MonoGame 3.7 for a while and haven't experienced the issue. Do you know the exact commit that causes it?
@dellis1972 @cra0zy - Any ideas?
I don't know the specifics of this issue. But could it be similar to the issues we had on NVTT with delegates being called back from native code?
See the following post for my fix for that:
https://github.com/MonoGame/MonoGame/issues/6093#issuecomment-372035048
I feel like this bug is gonna be hard to spot.
No idea if this is your specific issue, but you aren't storing the delegate used as the debug callback here: https://github.com/MonoGame/MonoGame/blob/b814336d78ead2b44f1aa3848a6dcfaa369f7e1f/MonoGame.Framework/Graphics/OpenGL.cs#L1344 I had a similar bug until I started storing the callback in a field before passing it to OpenGL.
https://github.com/mellinoe/veldrid/blob/master/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs#L899-L902
It looks like that MonoGame code is only active in Debug builds, though, so it could be unrelated.
I believe that's the issue, it's not stored and it's getting collected.
And I can confirm that this issue only happens while debugging. Release builds are totally fine.
Good call.
I've been running into this a lot lately, making debugging really annoying.
Based on @mellinoe finding, I submitted a PR that fixes the issue.
Most helpful comment
No idea if this is your specific issue, but you aren't storing the delegate used as the debug callback here: https://github.com/MonoGame/MonoGame/blob/b814336d78ead2b44f1aa3848a6dcfaa369f7e1f/MonoGame.Framework/Graphics/OpenGL.cs#L1344 I had a similar bug until I started storing the callback in a field before passing it to OpenGL.
https://github.com/mellinoe/veldrid/blob/master/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs#L899-L902
It looks like that MonoGame code is only active in Debug builds, though, so it could be unrelated.