Call MinGW's so file using C #, display the video data back to the WPF interface, and register the callback function. C + + encountered a problem with the delegate being reclaimed when invoking the callback function, prompting: "The garbage collection delegate of type has made a callback." This can cause application crashes, corruption, and data loss. When you pass a delegate to unmanaged code, the managed application must keep the delegates active until they are sure that they will not be called again. "
This issue occurs after a program has been running for some time. The effect that you see from the GDB debugger is that all variables are normal and run to the callback function segmentation fault
The OpenCV imshow display image is directly called through C + +, and the mat used is reconstructed by pointers and size, proving that data preparation is no problem and should be a callback function call
Online to see People's solutions:
- Defines a delegate as a member variable of static;
- Define the callback function as static;
- Allow GC to not reclaim delegated gc.keepalive (DISPLAY_CB);
- Add tags before variables:
- [ThreadStatic]
- static public MINGW.DISPLAY_CB DISPLAY_CB;
However, these methods can only resolve a single-threaded call to the callback function, in which case the VS2010 debugger pops up the error message, saying "the type of garbage collection delegate has a callback." This can cause application crashes, corruption, and data loss. When you pass a delegate to unmanaged code, the managed application must keep the delegates active until they are sure that they will not be called again. ”
In the dynamic library, the C + + code opens another thread to call the C # callback function, and the program will only pop up this window prompt:
So now we can only temporarily use C # to establish a worker thread, to actively invoke C + + functions, in C + + through semaphore blocking way to implement event triggering.
C # unmanaged cross-thread delegate debugging