Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent crash when navigating to a page containing images #9011

Closed
brabebhin opened this issue Jul 26, 2022 · 38 comments · Fixed by #12310
Closed

Intermittent crash when navigating to a page containing images #9011

brabebhin opened this issue Jul 26, 2022 · 38 comments · Fixed by #12310
Labels
area-controls-image Image control fixed-in-7.0.59 Look for this fix in 7.0.59! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@brabebhin
Copy link

brabebhin commented Jul 26, 2022

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 brabebhin added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jul 26, 2022
@mattleibow
Copy link
Member

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 mattleibow added area-image Image loading, sources, caching s/needs-info Issue needs more info from the author area-controls-image Image control labels Jul 26, 2022
@ghost
Copy link

ghost commented Jul 26, 2022

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 ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jul 26, 2022
@mattleibow mattleibow removed legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jul 26, 2022
@mattleibow mattleibow added this to the 6.0-servicing milestone Jul 26, 2022
@brabebhin
Copy link
Author

brabebhin commented Jul 26, 2022

@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

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jul 26, 2022
@hartez hartez changed the title Intermitent crash when navigating to a page containing images Intermittent crash when navigating to a page containing images Jul 27, 2022
@jfversluis jfversluis added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-attention Issue has more information and needs another look labels Jul 28, 2022
@ghost
Copy link

ghost commented Jul 28, 2022

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.

@jfversluis jfversluis removed this from the 6.0-servicing milestone Jul 28, 2022
@brabebhin
Copy link
Author

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

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Jul 28, 2022
@brabebhin
Copy link
Author

brabebhin commented Jul 29, 2022

(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
Copy link
Author

brabebhin commented Aug 1, 2022

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
Copy link
Author

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

@MUJaCHe66
Copy link

Same problem scrolling images in CollectionView.

@brabebhin
Copy link
Author

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

@brabebhin
Copy link
Author

Any news on this?

@cylix-lee
Copy link

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.🙏

@mavispuford
Copy link

mavispuford commented Sep 24, 2022

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.)

@willisra83
Copy link

@jfversluis Is a fix being worked on for this?

@activa
Copy link
Contributor

activa commented Oct 2, 2022

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.

@Az65iq
Copy link

Az65iq commented Oct 2, 2022

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.)

do you use it on android or windows ?

@mavispuford
Copy link

do you use it on android or windows ?

Just for Android. I've honestly not been testing my app on Windows yet, but the stack trace shows a bunch of Android native classes.

@dbullen-uk
Copy link

Getting the same issue as everyone else. Absolute show stopper for my app.

@jpxue
Copy link

jpxue commented Oct 12, 2022

Also encountering this issue on Android when cycling through a number of ImageSources which is really frustrating.
EDIT: Switched to FromStream() yet the error still persist. Only solution that I found was switching to GraphicsView

@Robbert-jansen
Copy link

Same issue here.

@FM1973
Copy link

FM1973 commented Oct 27, 2022

I had the same problem again.
Using an image with only one Size-Request (i.e. HeightRequest) and no aspect fit results in random errors.
When I set both: height- and widthrequest the error is gone. Doesn´t matter which kind of imagesource (uri, file etc.).

@ross8alex
Copy link

Having the same issue here. Using both size requests doesn't fix it, nor does FromUri() or anything else that I've found so far. Really looking like migrating back to Xamarin Forms is the only answer, which really sucks.

@mohachouch
Copy link
Contributor

I spent a few hours to analyze this problem.

This bug was created following this pull request: #7348

While waiting for Microsoft to permanently fix this bug, the workaround consists of redoing the clear before each source image change.

Below is an example of code to add the clear in the source image mapping.

This workaround is applicable to the following bug
#11519 #11130 #10032 #9712 #8809 #9011
#8178 #8809

using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;

namespace MauiCanvas;

public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
			.ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
				fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
			});

#if __ANDROID__
        ImageHandler.Mapper.PrependToMapping(nameof(Microsoft.Maui.IImage.Source), (handler, view) => PrependToMappingImageSource(handler, view));
#endif

        return builder.Build();
	}

#if __ANDROID__
    public static void PrependToMappingImageSource(IImageHandler handler, Microsoft.Maui.IImage image)
    {
        handler.PlatformView?.Clear();
    }
#endif

}

@hartez hartez moved this from Todo to In Progress in MAUI SDK Ongoing Dec 28, 2022
@github-project-automation github-project-automation bot moved this from In Progress to Done in MAUI SDK Ongoing Dec 28, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 27, 2023
@samhouts samhouts added the partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with label Feb 13, 2023
@samhouts samhouts added this to the .NET 7 + Servicing milestone Feb 13, 2023
@samhouts samhouts added fixed-in-7.0.59 Look for this fix in 7.0.59! fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! labels Feb 16, 2023
@Eilon Eilon removed the area-image Image loading, sources, caching label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-image Image control fixed-in-7.0.59 Look for this fix in 7.0.59! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet