Answer the question
In order to leave comments, you need to log in
How to create a reference to a delegate so that the garbage collector does not destroy it?
When resizing the application window, a delegate is called, which is passed to unmanaged code, and the program crashes with an error: A delegate of type "OPENGL_SDK!OPENGL_SDK.Glut+dReshapeFunc::Invoke" received by the garbage collector was called back. This can cause application crashes and data corruption or loss. When passing delegates to unmanaged code, a managed application must keep them alive until it is guaranteed that they will never be called again.
I can guess what needs to be done so that in managed code the delegate remains throughout the life of the program, but I do not know how to do this.
Answer the question
In order to leave comments, you need to log in
Keep a reference to this delegate in some global variable before passing it to unmanaged code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question