Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] Using GravitarImageSource causes AndroidRuntimeException leading to "white screen" issue

Open kfrancis opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Current Behavior

  • [Android] If you navigate to a page with a toolkit GravatarImageSource that is rendered immediately, there is an exception that causes navigation to other pages to fail in a specific way (blank white screen).

  • Exception

Android.Util.AndroidRuntimeException
  Message=Only the original thread that created a view hierarchy can touch its views.

 	0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception	C#
 	0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5	C#
 	0x1D in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23,26	C#
 	0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw	C#
 	0x89 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12324,5	C#
 	0x78 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:75,7	C#
 	0x12 in Android.Views.View.RequestLayout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.View.cs:20879,5	C#
 	0x8 in Microsoft.Maui.Platform.WrapperView.RequestLayout at D:\a\_work\1\s\src\Core\src\Platform\Android\WrapperView.cs:89,4	C#
 	0x8 in Android.Views.View.n_RequestLayout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.View.cs:20869,4	C#
 	0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:22,5	C#
 	0x37 in Java.Interop.NativeMethods.java_interop_jnienv_call_static_void_method_a	C#
 	0x54 in Java.Interop.JniEnvironment.StaticMethods.CallStaticVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:13246,4	C#
 	0x1A in Java.Interop.JniPeerMembers.JniStaticMethods.InvokeVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniStaticMethods.cs:97,4	C#
 	0x7B in Microsoft.Maui.PlatformInterop.LoadImageFromStream at D:\a\_work\1\s\src\Core\src\obj\Release\net7.0-android\generated\src\Microsoft.Maui.PlatformInterop.cs:443,5	C#
 	0xC8 in Microsoft.Maui.StreamImageSourceService.LoadDrawableAsync at D:\a\_work\1\s\src\Core\src\ImageSources\StreamImageSourceService\StreamImageSourceService.Android.cs:28,6	C#
 	0x11 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Maui.IImageSourceServiceResult>.AsyncStateMachineBox<Microsoft.Maui.StreamImageSourceService.<LoadDrawableAsync>d__0>.ExecutionContextCallback	C#
 	0x17 in System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop	C#
 	0x55 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Maui.IImageSourceServiceResult>.AsyncStateMachineBox<Microsoft.Maui.StreamImageSourceService.<LoadDrawableAsync>d__0>.MoveNext	C#
 	0x2 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Maui.IImageSourceServiceResult>.AsyncStateMachineBox<Microsoft.Maui.StreamImageSourceService.<LoadDrawableAsync>d__0>.ExecuteFromThreadPool	C#
 	0xC in System.Threading.ThreadPoolWorkQueue.DispatchWorkItem	C#
 	0x142 in System.Threading.ThreadPoolWorkQueue.Dispatch	C#
 	0x67 in System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart	C#
 	0x1F in System.Threading.Thread.StartHelper.RunWorker	C#
 	0x28 in System.Threading.Thread.StartHelper.Run	C#
 	0xF in System.Threading.Thread.StartCallback	C#

Expected Behavior

  • The gravatar image should render
  • Navigation to other pages by any other means should not be broken

Steps To Reproduce

  1. Open and run the solution in Android simulator/device: https://github.com/kfrancis/gravitar-appshell-repro
  2. Navigate using flyout to any other page

Expected: The gravatar image should be rendered as RoboHash immediately. There should be no exception being thrown. There should be no issue navigating away from and back to the main page with the Gravatar image source.

Actual: Exception is thrown, gravatar image is missing, navigating anywhere else gives the "white screen"

This is what it looks like: repro

Link to public reproduction project repository

https://github.com/kfrancis/gravitar-appshell-repro

Environment

- .NET MAUI CommunityToolkit: 5.1.0
- OS: Windows 11 Build 10.0.23526.1000 (doesn't seem related, can reproduce anywhere)
- .NET MAUI: net7 current

Anything else?

No response

kfrancis avatar Aug 24 '23 17:08 kfrancis

This does look to be partially fixed in net8 (preview 7) but the image source is still not working. The only thing that's fixed is that the exception doesn't cause more major issues. Still not rendering the gravatar:

reproNet8P7

kfrancis avatar Aug 24 '23 18:08 kfrancis

I think this is related to the .NET MAUI bug [Android] Image can disappear when going back to the page., as I can only get the image to "not" appear in the repo, when navigating away from the page and back again. Also note, that if you supply the email, and it's not a valid Gravatar email registered address, it returns a 404 and thus an image not found.

GeorgeLeithead avatar Mar 08 '24 17:03 GeorgeLeithead

Thanks @GeorgeLeithead! We'll circle back to this issue once the .NET MAUI bug has been resolved.

TheCodeTraveler avatar Mar 08 '24 17:03 TheCodeTraveler