I've found an AV in https://github.com/AvaloniaUI/Avalonia/issues/1320 that's caused by SharpDX. It's happening in SharpDX.WIC.BitmapDecoder, so it's not in Avalonia's control. Here's what's happening:
If the ICallbackable native shadow thunk(s) are finalized before the ComObject is finalized, then we get an access violation when the ComObject is finalized and the Native COM object tries to call Release on the native shadow thunk for the ICallbackable object.
Suggested Fix: Only de-allocate native shadow thunks once the refcount hits 0 instead of when dispose is called.
I've found an AV in https://github.com/AvaloniaUI/Avalonia/issues/1320 that's caused by SharpDX. It's happening in
SharpDX.WIC.BitmapDecoder
, so it's not in Avalonia's control. Here's what's happening:General object layout:
SharpDX
ComObject
(wraps) Native COM object (has reference to) Native Thunk (for)ICallbackable
object.If the
ICallbackable
native shadow thunk(s) are finalized before theComObject
is finalized, then we get an access violation when theComObject
is finalized and the Native COM object tries to callRelease
on the native shadow thunk for theICallbackable
object.Suggested Fix: Only de-allocate native shadow thunks once the refcount hits 0 instead of when dispose is called.