This repository has been archived by the owner on May 1, 2024. It is now read-only.
[Android] Prevent ObjectDisposedException in ButtonBackgroundTracker #1040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
Fixes an ObjectDisposedException thrown in the
ButtonDrawable.Draw
method. The drawable itself is held by the new classButtonBackgroundTracker
introduced in the refactoring PR #941 in XF 2.3.5.255-pre5.Inside the
UpdateDrawableMethod()
, the field_backgroundDrawable
is used to hold a reference to the drawable. Previously, we only recreate the drawable if it was null however this does not account for edge cases where the object has been disposed but is not null.To ensure we have a valid instance of
ButtonDrawable
, we initialise a new instance.Note: I experimented with simply checking the handle for IntPtr.Zero at this point, but this is not 100% effective. It appears there are certain cases whereby the object can be disposed between
_nativeButton.SetBackground(_backgroundDrawable);
and the native `Draw()' method being invoked.This is particular noticeable when using advanced layout mechanisms such as Android's
RecyclerView
.Bugs Fixed
https://bugzilla.xamarin.com/show_bug.cgi?id=57789
API Changes
None
Behavioral Changes
None
PR Checklist