softlion / XamSvg-Samples

Samples for Xamarin Svg enterprise cross platform and full featured Svg image control
https://vapolia.eu
MIT License
24 stars 4 forks source link

Cannot access a disposed object. Object name: 'UISvgImageView'. #9

Closed JulesMoorhouse closed 3 years ago

JulesMoorhouse commented 3 years ago

I'm getting an error when using XamSvg, it occurs when I have the System.Exception breakpoint enabled. Whereas previously the error didn't occur. I'm not sure whats changed.

Cannot access a disposed object.
Object name: 'UISvgImageView'.

I'm using VS for Mac 2019 8.8.5 Vapolia.XamSvg.Forms 3.1.8 Xamarin.Forms 5.8.0.1451

The full error is...

  at Foundation.NSObject.get_SuperHandle () [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/Foundation/NSObject2.cs:394 
  at UIKit.UIImageView.set_Image (UIKit.UIImage value) [0x00033] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIImageView.g.cs:373 
  at XamSvg.UISvgImageView.UpdateImageAsync2 (System.Threading.CancellationToken cancelToken) [0x00313] in <a5cec8294a354b20868caefc5c5cf3cc>:0 

Any ideas ?

softlion commented 3 years ago

This is mostly caused by a bad known behavior of the MONO debugger, which likes to dispose objects it does not own, or leaves the context before the breakpoint really occurs, or if you enabled the linker.

It is not caused by XamSvg.

JulesMoorhouse commented 3 years ago

I'd just like to take this opportunity to thank you for you're work on XamSvg, it's awesome.

Oh I hadn't thought the Mono debugger was used for iOS.

We have had similar issues with our own platform code, but I think this has been exclusively for Android. In these scenarios simply adding an Overide and the super base call, swallow the error.

Obviously this isn't something we can add to XamSvg, is this something you could add ? Or have you any other ideas how to silence the error, without disabling the linker..

Thanks in advance!!

softlion commented 3 years ago

simply adding an Overide and the super base call, swallow the error

Which method are you overriding ?

JulesMoorhouse commented 3 years ago

I think these are similar issues...

https://github.com/xamarin/Xamarin.Forms/issues/12059 https://github.com/xamarin/Xamarin.Forms/issues/12044

In this case we added ...

public CustomTimePickerRenderer(IntPtr handle, JniHandleOwnership transfer)

But as I say this was for Android

softlion commented 3 years ago

Oh ok, all the "invisible" but required constructors are already present, on both iOS and Android.

JulesMoorhouse commented 3 years ago

So what now? can you add something. Or can we ?

Thanks.

softlion commented 3 years ago

The last time i saw this issue is when i was using xamsvg in a collectionview's item, and i was changing to another page. Xamarin Forms incorrectly asynchronously updates the collection view items that are in a collectionview which is disposed or detached from its parent.

I know it's hard to believe, but it's not an issue with the Svg component.

I fixed it by making sure the page is attached to its parent before it is displayed. Note that you can update to Xamarin Forms 5 too to fix the issue, as the Forms team fixed this issue with collection views.

JulesMoorhouse commented 3 years ago

How do I attach a page to it’s parent ?

softlion commented 2 years ago

Don't mind, it's fixed now.