Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Crash in iOS's EntryRenderer due to "NSRangeException Reason: Cannot remove an observer ... for the key path "sublayers" from <CALayer 0x600007b11e80> because it is not registered as an observer." #14804

Closed
lee-m opened this issue Oct 29, 2021 · 19 comments · Fixed by #14828

Comments

@lee-m
Copy link
Contributor

lee-m commented Oct 29, 2021

Description

The changes in PR #14526 added an observer to the ClearButton on an Entry to ensure correct tinting of the clear button which was released in SR6.

After updating to SR6 I'm seeing the following crash on iOS 12.5.5:

Name: NSRangeException Reason: Cannot remove an observer ... for the key path "sublayers" from <CALayer 0x600007b11e80> because it is not registered as an observer.

It happens on EntryRenderer Dispose call at this line:
ClearButton?.Layer?.RemoveObserver(this, new NSString("sublayers"));

Steps to Reproduce

Expected Behavior

Application should not crash.

Actual Behavior

Crashes with the reported error.

Basic Information

  • Version with issue: Xamarin.Forms 5.0.0.2196 (SR6)
  • Platform Target Frameworks:
    • iOS: 15
  • NuGet Packages: Xamarin.Forms 5.0.0.2196 (SR6)
  • Affected Devices: iPhone 6 running iOS 12.5.5

Reproduction Link

Workaround

None as yet.

@lee-m lee-m added s/unverified New report that has yet to be verified t/bug 🐛 labels Oct 29, 2021
@jfversluis
Copy link
Member

Thanks! Please ping me when you have reproduction steps and ideally a small project repro :)

@lee-m
Copy link
Contributor Author

lee-m commented Oct 29, 2021

Attached is the top part of the callstack. Trying to include it inline renders is unreadable due to excessive word-wrapping.

In my application, I'm using BindableLayout where the template for each item includes an Entry. Setting the property which is bound to the ItemsSource to something is when the crash happens.

CallStack.txt

@jfversluis
Copy link
Member

Thanks for the strack trace, I'd still like to have a repro if you can provide it though. From a first quick test I'm not able to reproduce it immediately.

@lee-m
Copy link
Contributor Author

lee-m commented Nov 3, 2021

I'm still trying to reduce down our app to something that repro's the crash but it's proving a bit time-consuming trying to peel back several custom controls and effects that are all being used on the crashing page to pinpoint the exact cause.

@jfversluis
Copy link
Member

Alright, thanks! :)

I have dug into the code and might have a possible fix. I will put it in a PR in a little. If I could ask you to download the NuGet that results from that and test it for me that would be amazing!

@stavroaudisho
Copy link

stavroaudisho commented Nov 11, 2021

I updated XF to 5.0.0.2196 and just experienced this issue (not sure if they are relevant). When will there be a fix?

Downgrading to 5.0.0.2125 for now

@jfversluis
Copy link
Member

Should be released early next week. Thanks!

@Alex-Dobrynin
Copy link

Alex-Dobrynin commented Nov 18, 2021

@jfversluis in v5.0.0.2244 keep crashing iOS 13.5, 13.6.1 not fixed
image
image

@jfversluis
Copy link
Member

Correct, see #14887 please try the current nightly build

@aperel66
Copy link

aperel66 commented Dec 1, 2021

Meanwhile, is there some sort of a workaround?
Like is there a method in the renderer that we can put a try/catch to extinguish this exception?

@jfversluis
Copy link
Member

Meanwhile, is there some sort of a workaround? Like is there a method in the renderer that we can put a try/catch to extinguish this exception?

Either downgrade or use the nightly version. I'm thinking of releasing the new version a bit earlier tbh. Running the tests now maybe I can already do the update next week. Either way it would be great to know if the current nightly version fixes the problem for you @aperel66

@VitalyKnyazev
Copy link
Contributor

VitalyKnyazev commented Dec 1, 2021

Meanwhile, is there some sort of a workaround? Like is there a method in the renderer that we can put a try/catch to extinguish this exception?

This works for me even in Release build.
Just try/catch still crashes in Release by some reason so simply not calling Dispose for older iOS.

protected override void Dispose(bool disposing) { if(VersionCheck.IsiOS14OrNewer) base.Dispose(disposing); }

@aperel66
Copy link

aperel66 commented Dec 1, 2021 via email

@aperel66
Copy link

aperel66 commented Dec 1, 2021 via email

@maxholtman
Copy link

maxholtman commented Feb 23, 2022

I am also encountering this issue and the snippet @VitalyKnyazev posted above worked for me...my only question is - are there harmful side effects to not disposing this object to alleviate this issue? Not disposing resources seems like a memory leak that could cause issues. Going to try looking into EntryRenderer's source code but I thought I might as well ask it here, too. @jfversluis

@bitshftr
Copy link

This issue seems to be "closed" as I write this on 02/24/2022. What released version of Xamarin.Forms contains this fix?

@lee-m
Copy link
Contributor Author

lee-m commented Feb 24, 2022

@bitshftr This was fixed in SR8

@bitshftr
Copy link

^ Does that equate to Xamarin.Forms Version 5.0.0.2291 ?

@rahou25
Copy link

rahou25 commented Apr 22, 2022

this solves the issue as the error is unhandled.

protected override void Dispose(bool disposing)
        {
            try
            {
                base.Dispose(disposing);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

put it in the xamarin.ios render extension class.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i/regression p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛
Projects
No open projects
9 participants