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

Java.Lang.RuntimeException Message=Canvas: trying to use a recycled bitmap android.graphics.Bitmap@5d9bccf #13534

Closed
RodBarnes opened this issue Feb 23, 2023 · 11 comments
Labels
area-controls-image Image control platform/android 🤖 s/needs-attention Issue has more information and needs another look s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working

Comments

@RodBarnes
Copy link

RodBarnes commented Feb 23, 2023

Description

NOTE: Searched for matching issues and found issue #9007. But it was closed in favor of #9011 which was closed without any apparent resolution? I tried the workaround found there #9011 (comment) but couldn't get it to build.

This only happens when deployed to an device (Android 12). It doesn't happen on the emulator (API 31). The project is targeting .NET 6 since .NET 7 does not support API 31.

Visually, the error occurs when scrolling through a CollectionView of images.

I did find a workaround but it is subtle and only discovered by digging around. The image reuse should work without this workaround and forcing the developer to "guess" what to do to fix it.

Steps to Reproduce

  1. Clone the repo, build in debug, and deploy to a device (e.g., Samsung S10+ Android 12).
  2. Run the app.
  3. Tap menu, tap "Parks".
  4. Tap tile showing "Adams".
  5. Tap [Images] button to display the images.
  6. Scroll down and it aborts with the error.

Same error can be manifested on all image lists that have seven(?) or more images; i.e., enough images that the list has to be reused.

Link to public reproduction project repository

https://github.com/RodBarnes/NationalParks

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

API 31, Android 12

Did you find any workaround?

I found that by adding a HeightRequest attribute to the image I could keep this from happening. Which is great, but there is nothing that would tell me that is the correct thing to do without digging around. In the output (included below), I saw a statement for each image that was viewed that spoke about the image size being a consideration. So that led me to consider adding a HeightRequest or WidthRequest. But the WidthRequest did not work. Subsequently, I see the #9011 (comment) where someone else stumbled upon this.

Relevant log output

[CustomViewTarget] Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use .override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.
@RodBarnes RodBarnes added the t/bug Something isn't working label Feb 23, 2023
@samhouts
Copy link
Member

We believe that #9011 was resolved in a PR that was released in 7.0.59. Can you please confirm that you're using that version? Thanks!

@samhouts samhouts added s/needs-info Issue needs more info from the author legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-image Image control labels Feb 24, 2023
@ghost
Copy link

ghost commented Feb 24, 2023

Hi @RodBarnes. 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.

@RodBarnes
Copy link
Author

Opened terminal and did dotnet workload list (see below). It is all 7.0.59.

**********************************************************************
** Visual Studio 2022 Developer PowerShell v17.5.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
PS E:\Source\GitHub\NationalParks> dotnet workload list

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
wasm-tools                 7.0.3/7.0.100          VS 17.5.33414.496
ios                        16.2.1024/7.0.100      VS 17.5.33414.496
maccatalyst                16.2.1024/7.0.100      VS 17.5.33414.496
maui-windows               7.0.59/7.0.100         VS 17.5.33414.496
maui-maccatalyst           7.0.59/7.0.100         VS 17.5.33414.496
maui-ios                   7.0.59/7.0.100         VS 17.5.33414.496
android                    33.0.26/7.0.100        VS 17.5.33414.496
maui-android               7.0.59/7.0.100         VS 17.5.33414.496
wasm-tools-net6            7.0.3/7.0.100          VS 17.5.33414.496

Use `dotnet workload search` to find additional workloads to install.

@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 Feb 25, 2023
@hartez
Copy link
Contributor

hartez commented Feb 25, 2023

The project is targeting .NET 6 since .NET 7 does not support API 31.

If you target .NET 7, does the problem persist? The PR which fixed this issue (#12310, referenced here) was backported to .NET 7, but not .NET 6.

@hartez hartez added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Feb 25, 2023
@ghost
Copy link

ghost commented Feb 25, 2023

Hi @RodBarnes. 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.

@RodBarnes
Copy link
Author

RodBarnes commented Feb 25, 2023

Targeting .NET 7 it does not exhibit the issue. What is the chance of getting this backported to .NET 6? That is the LTS and it isn't possible to target Android 12/API 31 without targeting .NET 6 -- they're joined at the hip. There are a lot of Android 12 devices still out there in use as they are only a couple years old.

@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 Feb 25, 2023
@samhouts
Copy link
Member

samhouts commented Feb 27, 2023

@RodBarnes Please take a look at this article about Android API versions--this document mentions Xamarin, but this is actually an Android convention that applies to .NET MAUI, too. It can certainly be confusing!

The TLDR; is that you can (and should) compile with the latest version of Android, but that does not limit the minimum API that your app can run on. If you target API 31 or 32+, your .NET MAUI app will still be able to run on devices as early as API 21. In other words, you do not have to target .NET 6 to ensure that your apps run on Android 12 devices.

.NET MAUI uses the modern lifecycle, so we always recommend updating to the latest stable version as soon as possible. Please let us know if you encounter any other blockers to updating to .NET 7, and we'll consider backporting this to .NET 6 at that time.

Thanks!!

@samhouts samhouts added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Feb 27, 2023
@ghost
Copy link

ghost commented Feb 27, 2023

Hi @RodBarnes. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

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.

@RodBarnes
Copy link
Author

Understood. I will make another attempt and report back.

@RodBarnes
Copy link
Author

Yes, that works. It's been a few years since I'd built an Android app (early days of Xamarin) and forgotten about the target/minimum thing on the API. Setting the target to .NET 7/API 33 with minimum API 29 built and ran fine. And now the original issue is gone. Thanks for the kind reminder and for the fix as well.

@samhouts
Copy link
Member

Wonderful!! Thank you so much for getting back to us. Happy coding!!!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 30, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor 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 platform/android 🤖 s/needs-attention Issue has more information and needs another look s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants