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

[android] Identified crash in toolbar extensions when using a custom image source #22138

Closed
softlion opened this issue Apr 30, 2024 · 7 comments
Labels
area-controls-toolbar ToolBar platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@softlion
Copy link
Contributor

Description

On Android, when using a custom image source as the source for an IconImageSource of a Toolbar item, and that source does not implement GetConstantState, maui crashes:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                     xmlns:svg="https://vapolia.eu/svg">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{x:Static appresource:AppResources.Home_Filter}" 
                     Command="{Binding OpenFilterViewCommand}" 
                     Order="Primary"
                     IconImageSource="{svg:Svg my_icon.svg}" />
    </ContentPage.ToolbarItems>

Steps to Reproduce

The issue is caused by the code in
https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs

which ignores the null value returned by baseDrawable.GetConstantState() as not all custom drawable implements that caching feature.

image

Instead, it should not ignore the null value, and provides an alternate implementation when GetConstantState() returns null

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android all versions

Did you find any workaround?

no

Relevant log output

04-30 10:56:46.028 I/DOTNET  (19040): 97|2024-04-30T10:56:46.0278601+00:00|ERROR|1|IImageSource|Unexpected exception in LoadImage. --> System.NullReferenceException: Object reference not set to an instance of an object.
04-30 10:56:46.028 I/DOTNET  (19040):    at Microsoft.Maui.Controls.Platform.ToolbarExtensions.<>c__DisplayClass13_0.<UpdateMenuItemIcon>b__0(IImageSourceServiceResult`1 result) in D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\Extensions\ToolbarExtensions.cs:line 366
04-30 10:56:46.028 I/DOTNET  (19040):    at Microsoft.Maui.ImageSourceExtensions.LoadImageResult(Task`1 task, Action`1 finished) in D:\a\_work\1\s\src\Core\src\ImageSources\ImageSourceExtensions.cs:line 32
04-30 10:56:46.028 I/DOTNET  (19040):    at Microsoft.Maui.TaskExtensions.FireAndForget(Task task, Action`1 errorCallback) in D:\a\_work\1\s\src\Core\src\TaskExtensions.cs:line 36
@PureWeen
Copy link
Member

PureWeen commented May 2, 2024

/similarissues

Copy link
Contributor

github-actions bot commented May 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@PureWeen PureWeen added the s/needs-repro Attach a solution or code which reproduces the issue label May 3, 2024
@softlion
Copy link
Contributor Author

softlion commented May 3, 2024

The repro is in the comment. Along with the line where the bug is.

@dotnet-policy-service dotnet-policy-service bot 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 May 3, 2024
@PureWeen PureWeen 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 May 7, 2024
@PureWeen
Copy link
Member

PureWeen commented May 7, 2024

@softlion can you attach a full project please?

@softlion
Copy link
Contributor Author

softlion commented May 7, 2024

Man, the issue is so obvious - I pointed the exact line in the maui source code - that i won't spend 1 more hour on it.

The maui code voluntarily ignores the null return value with an exclamation mark. If it can return null, why ignore it ?

I'm the publisher of a custom component that creates a full custom imagesource with a custom android Drawable.
I already updated my component so it now implements that optional Drawable override, So that issue is worked around.

@dotnet-policy-service dotnet-policy-service bot 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 May 7, 2024
@PureWeen
Copy link
Member

PureWeen commented May 7, 2024

So that issue is worked around.

Good to hear!

@PureWeen PureWeen closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@softlion
Copy link
Contributor Author

softlion commented May 7, 2024

So that issue is worked around.

Good to hear!

Do you have a financial bonus when you close an issue ?

I would like to understand why you dont add a if( xxxx is not null ) in the source code instead of leaving that bug there and closing that issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-toolbar ToolBar platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants