maui icon indicating copy to clipboard operation
maui copied to clipboard

Intermittent crash when navigating to a page containing images

Open brabebhin opened this issue 2 years ago โ€ข 37 comments

Description

I randomly get this error when navigating to a content page that displays an image twice (uses same URL for the image but with technically using 2 different instances).

This seems to originate from the version of glide built into MAUI

Steps to Reproduce

https://github.com/brabebhin/maui-andoid-image-crash

Run the app. The first time you run it, navigate to the 2nd tab, and wait it out until it generates its 1000 images. Once the images pop up, start scrolling the list. While the list is scrolling, go to the first tab, click the button several times then go back to the second tab and scroll back up.

Repeat until the crush occurs. I've noticed there's a higher chance if your phone is in landscape mode. DO try this on a phone (i tried on Samsung galaxy note 10+). Don't know if it can be done on emulator.)

Version with bug

6.0.408 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12

Did you find any workaround?

Nope.

Relevant log output

[TabLayout] MODE_SCROLLABLE + GRAVITY_FILL is not supported, GRAVITY_START will be used instead
**Java.Lang.RuntimeException:** 'Canvas: trying to use a recycled bitmap android.graphics.Bitmap@16f3485'

[Bitmap] Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
[Bitmap] Called getConfig() on a recycle()'d bitmap! This is undefined behavior!

Stack trace:


 	0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw	C#
 	0x8E in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12324,5	C#
 	0x65 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:35,5	C#
 	0x38 in Android.Views.View.DispatchDraw at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-33/mcw/Android.Views.View.cs:14916,5	C#
 	0x11 in Microsoft.Maui.Platform.ContentViewGroup.DispatchDraw at D:\a\_work\1\s\src\Core\src\Platform\Android\ContentViewGroup.cs:41,4	C#
 	0x11 in Android.Views.View.n_DispatchDraw_Landroid_graphics_Canvas_ at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-33/mcw/Android.Views.View.cs:14904,4	C#
 	0x9 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:121,5	C#
 	0x3A in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_boolean_method_a	C#
 	0x79 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualBooleanMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11969,4	C#
 	0x65 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:75,5	C#
 	0x70 in Android.Views.ViewGroup.DrawChild at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-33/mcw/Android.Views.ViewGroup.cs:2824,5	C#
 	0x4 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.DrawChild at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRenderer.cs:171,4	C#
 	0x1C in Android.Views.ViewGroup.n_DrawChild_Landroid_graphics_Canvas_Landroid_view_View_J at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-33/mcw/Android.Views.ViewGroup.cs:2809,4	C#
 	0xD in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLJ_Z at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:308,5	C#

brabebhin avatar Jul 26 '22 19:07 brabebhin

Does this have issues with all images? Just to be safe when we test, can you provide the link to an image that fails - even if it is not your actual image.

Does it happen on a blank page with 2 image views, or is this image being used by additional UI elements - like shell icons, tabs or something else?

mattleibow avatar Jul 26 '22 19:07 mattleibow

Hi @brabebhin. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Jul 26 '22 19:07 ghost

@mattleibow any image will do.

This is usually easy to reproduce with a shell app with 2 tabs. On one tab, a collection view with images. On the second tab, 2 images with same source file. While scrolling the list in the first tab, switch to the second tab. It is important that the collection view contains an image linked to the source of the 2 images in the other tab.

I will try to create a simple app to demonstrate the issue but it is similar to #9007 #8809

brabebhin avatar Jul 26 '22 19:07 brabebhin

Hi @brabebhin. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Jul 28 '22 18:07 ghost

Ok, I will try to create a simple reproduce sample in the weekend.

brabebhin avatar Jul 28 '22 19:07 brabebhin

(this looks like a thread race to me)

Some more stack traces

`07-29 21:19:23.403 9505 9505 E AndroidRuntime: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@106bd9d 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:87) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:263) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:97) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:560) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.widget.ImageView.onDraw(ImageView.java:1444) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23898) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at crc64e1fb321c08285b90.FrameRenderer.n_draw(Native Method) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at crc64e1fb321c08285b90.FrameRenderer.draw(FrameRenderer.java:65) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.widget.HorizontalScrollView.draw(HorizontalScrollView.java:2238) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at androidx.core.widget.NestedScrollView.draw(NestedScrollView.java:2112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at crc6452ffdc5b34af3a0f.ContentViewGroup.n_dispatchDraw(Native Method) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at crc6452ffdc5b34af3a0f.ContentViewGroup.dispatchDraw(ContentViewGroup.java:55) 07-29 21:19:23.403 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at crc6452ffdc5b34af3a0f.ContentViewGroup.n_dispatchDraw(Native Method) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at crc6452ffdc5b34af3a0f.ContentViewGroup.dispatchDraw(ContentViewGroup.java:55) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5204) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4603) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1312) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at androidx.drawerlayout.widget.DrawerLayout.drawChild(DrawerLayout.java:1478) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at crc640ec207abc449b2ca.ShellFlyoutRenderer.n_drawChild(Native Method) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at crc640ec207abc449b2ca.ShellFlyoutRenderer.drawChild(ShellFlyoutRenderer.java:54) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22753) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23628) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.drawChild(ViewGroup.java:5355) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewGroup.dispatchDraw(ViewGroup.java:5112) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.draw(View.java:23901) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at com.android.internal.policy.DecorView.draw(DecorView.java:1377) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.View.updateDisplayListIfDirty(View.java:22767) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:602) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:608) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:684) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewRootImpl.draw(ViewRootImpl.java:5432) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:5140) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4204) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2911) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10458) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:866) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:797) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:226) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.os.Looper.loop(Looper.java:313) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8663) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567) 07-29 21:19:23.404 9505 9505 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

`

brabebhin avatar Jul 29 '22 18:07 brabebhin

Hi @jfversluis

It took me some time to do it but here's the sample

https://github.com/brabebhin/maui-andoid-image-crash

Run the app. The first time you run it, navigate to the 2nd tab, and wait it out until it generates its 1000 images. Once the images pop up, start scrolling the list. While the list is scrolling, go to the first tab, click the button several times then go back to the second tab and scroll back up.

Repeat until the crush occurs. I've noticed there's a higher chance if your phone is in landscape mode. DO try this on a phone (i tried on Samsung galaxy note 10+). Don't know if it can be done on emulator.

brabebhin avatar Aug 01 '22 13:08 brabebhin

Any progress on this? MAUI is essentially unusable on Android.

brabebhin avatar Aug 03 '22 15:08 brabebhin

Same problem scrolling images in CollectionView.

MUJaCHe66 avatar Aug 11 '22 12:08 MUJaCHe66

Yes. I suspect scrolling plays a part too, but sometimes there's no list involved. This is very annoying bug.

brabebhin avatar Aug 11 '22 12:08 brabebhin

Any news on this?

brabebhin avatar Aug 19 '22 15:08 brabebhin

I encountered this too. I tried to use GraphicsView to draw images manually, but on the one hand the Image.Resize method always throws an ObjectDisposedException, on the other hand the image diaplayed is just like a pixel-art. Maybe it's because GraphicsView does not support hidpi or whatever.

BTW, I'm thinking of migrating back to Xamarin. It's just so urgent for me to get my app working without this fatal bug.๐Ÿ˜ฅ Does anybody know if Xamarin has the same problem too? Any useful information on this will be highly appreciated.๐Ÿ™

cylix-lee avatar Aug 24 '22 18:08 cylix-lee

I found a work around.

Don't use FromFile when creating the image source. That is totally bugged.

But you can use FromUri with a scheme pointing to file. For android, i can use content:\pathtofile.

Even if you do use from Uri, don't display the same image twice. I suspect it will work if you save the image in 2 different locations and essentially have the same bitmap but different uri.

In any case, I decided to use react native instead. It's quite obvious maui/xamarin forms isn't going to be production ready for the foreseeable future. It's a shame really.

brabebhin avatar Aug 24 '22 19:08 brabebhin

It worked! Thank you so much!

The first problem is exactly the FromFile, but I didn't make it to use Uri. However, FromStream worked too. As you said, I saved the image file every time I loaded it, and crushes caused by displaying it twice were gone.

The second problem is probably about image caching, I think. Even though I didn't play an image twice, switching to a page containing images loaded a long time ago causes crash to. Setting the Image control invisible when the page Disappearing, and perform save, reload, and set Image visible when page Appearing seems to solve this somewhat.

Anyway, thank you so much for your commitment! That helped me a lot!

(Well, I hope this bug can be fixed officially ASAP. It's avoidable, but it's still a BUG after all!)

cylix-lee avatar Aug 25 '22 15:08 cylix-lee

I tried fromStream but didn't really work for me. I guess i didn't do the IsVisible part. Either way, I hope this doesn't get resolved with this as a work around.

brabebhin avatar Aug 25 '22 19:08 brabebhin

I have the same issue. I load a list of items from API call, the image URL points to an external URL so I'm not using FromFile at all. just trying to display items in a CollectionView. The app crashes with the same error when I scroll a little bit.

Giorgi avatar Aug 28 '22 13:08 Giorgi

Since I started using FromUri and no double images, it's been pretty stable for me.

brabebhin avatar Aug 28 '22 15:08 brabebhin

I have the same issue. I load a list of items from API call, the image URL points to an external URL so I'm not using FromFile at all. just trying to display items in a CollectionView. The app crashes with the same error when I scroll a little bit.

same here, I am calling a binding from XAML part of the project, thus no workarounds I guess?

Yekez avatar Aug 29 '22 16:08 Yekez

This is how I bind my list. I.E. Directly to an ImageSource.

I have no idea why it is not formatting.

public ImageSource ImageSourceInstance { get { if (imageSource == null) { imageSource = ImageSource.FromUri(string.IsNullOrWhiteSpace(ImageUri) ? new Uri(fallbackImage) : new Uri(ImageUri);

            }
            return imageSource;
        }
    }

brabebhin avatar Aug 29 '22 17:08 brabebhin

Same here, but Iยดm not using a collection. I got some sort of "BannerService" which loads images via a rest service. When I try to change the image binding, the error occurs. Very annoying!

FM1973 avatar Aug 31 '22 11:08 FM1973

In my case, I get an images as a byte[] from the server. Bind it like this in my SomethingModel:

public byte[] Thumb { get; set; }
public ImageSource Thumbnail
		{
			get
			{
				if(Thumb == null) 
					return null;
				return ImageSource.FromStream(() => new MemoryStream(Thumb));
			}
		}

I dynamically request more images if needed page by page. Everything is displayed in CollectionView in the end. Sometimes - it just crashes mid scrolling data. Every Item in CollectionView is a different object from the server, so not a single item should share the ImageSource. So the cause of the crash should be the scrolling part

MissedSte4k avatar Sep 05 '22 08:09 MissedSte4k

Yes. I suspect this has something to do with scrolling and possibly reusing of images during scroll.

brabebhin avatar Sep 07 '22 19:09 brabebhin

I've also been getting this exception in my app. I'm using an Image inside an ItemTemplate for a FlexLayout. Up to nine images are shown at a time. I'm using ImageSource.FromFile(filePath) to set up my ImageSources. The contents of the FlexLayout get wiped out often as new queries are made by the user. After a time, the app will throw the above exception and crash.

mavispuford avatar Sep 08 '22 20:09 mavispuford

It seems like this bug does not exist in Xamarin... That's funny.

cylix-lee avatar Sep 09 '22 08:09 cylix-lee

I found the following #9712 In my case I know the height and width and when I set both as a "request" the error goes away.

FM1973 avatar Sep 20 '22 12:09 FM1973

Setting a HeightRequest + WidthRequest does not work for me, unfortunately... ๐Ÿ™

mavispuford avatar Sep 22 '22 20:09 mavispuford

Today i also get bug ""Java.Lang.RuntimeException: 'Canvas: trying to use a recycled bitmap android.graphics.Bitmap", I use "image.Source = null" before set source to solve it, see https://github.com/dotnet/maui/issues/9712#issuecomment-1256885920

xtuzy avatar Sep 24 '22 07:09 xtuzy

Setting the ImageSource to null didn't seem to help me either.

HOWEVER, I found a solution that does work in my case. I'm using SkiaSharp for image manipulation stuff, and I just discovered that they have SKBitmapImageSource. So I switched over to that instead and my crashes are gone! ๐ŸŽ‰

My code now looks like this:

        var imageSource = new SKBitmapImageSource
        {
            Bitmap = SKBitmap.Decode(imageBytes)
        };
        result.ImageSource = imageSource;

SKBitmap.Decode() can also take in several other types (Streams, file names, etc.)

mavispuford avatar Sep 24 '22 07:09 mavispuford

@jfversluis Is a fix being worked on for this?

willisra83 avatar Oct 02 '22 17:10 willisra83

This is a blocking issue on Android. Incredibly easy to reproduce: a collection view with multiple images loaded from a Uri will 100% crash the app every single time.

activa avatar Oct 02 '22 17:10 activa