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

[Android AppCompat] Add defensive code to prevent NRE in GetNativeSize #14933

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ public static SizeRequest GetNativeSize(VisualElement view, double widthConstrai
{
Performance.Start(out string reference);

// FIXME: potential crash
IVisualElementRenderer visualElementRenderer = Android.Platform.GetRenderer(view);

if (visualElementRenderer == null || visualElementRenderer.View.IsDisposed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know when this happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I see it in the stack traces of the mentioned issues and this code was implemented for the fast renderers but not here. So I guess it doesn't hurt :)

{
return new SizeRequest(Size.Zero, Size.Zero);
}

var context = visualElementRenderer.View.Context;

// negative numbers have special meanings to android they don't to us
Expand Down