Callback being made on a garbage collected delegate of PromiseChangeFuncNative
Submitted by Krzysztof Z
Link to original bug (#797322)
Description
Created attachment 374005
Code I'm basing on
I'm using a slightly modified version of Centriculars WebRTCSendRecv example. When debugging, about 2/3 of the times, I'm getting the following exception:
'CallbackOnCollectedDelegate' : 'A callback was made on a garbage collected
delegate of type 'gstreamer-sharp!GstSharp.PromiseChangeFuncNative::Invoke'.
This may cause application crashes, corruption and data loss. When passing
delegates to unmanaged code, they must be kept alive by the managed
application until it is guaranteed that they will never be called.'
It happens exactly when OnOfferCreated should be called back, but as I said, it doesn't happen every time. It might be that specificity of my code causes that GC sometimes kicks in at a specific moment (?).
I think I'm safe to assume that it is not my mistake because keeping a handle to PromiseChangeFuncNative should be done by PromiseChangeFuncWrapper class after I provide PromiseChangeFunc delegate. What I understand should happen here is PersistUntilCalled() should be called somewhere but it is not.
I'm attaching the code that I'm basing on (from their github). I haven't modified OnNegotiationNeeded and OnOfferCreated methods at all, other parts are only slightly modified to get data from custom appsrc but I am unable to provide the exact code.
Attachment 374005, "Code I'm basing on":
WebRTCSendRecv.cs
Version: 1.14.x