dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

[graphics] PlatformCanvas.DrawImageCallback throws System.NullReferenceException when using ImagePaint on Mac/iOS #19642

Open peterblazejewicz opened 10 months ago

peterblazejewicz commented 10 months ago

Description

when using canvas from platform drawables, like in Maui 8.0 GraphicsViewDemos, whenever ImagePain is used on iOS/Mac (works on Android implementation), platform throws:

Object reference not set to an instance of an object. (System.NullReferenceException)
   at Microsoft.Maui.Graphics.Platform.PlatformCanvas.DrawImageCallback(CGContext context)
   at CoreGraphics.CGPattern.DrawCallback(IntPtr voidptr, IntPtr cgcontextptr) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/CoreGraphics/CGPattern.cs:line 144
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at GraphicsViewDemos.Program.Main(String[] args) in /Users/blazejewicz/develop/maui-samples/8.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Platforms/MacCatalyst/Program.cs:line 13

so here: https://github.com/dotnet/maui/blob/39440043ce9f69f0c8f275bc5a4dd083bdae1c7e/src/Graphics/src/Graphics/Platforms/MaciOS/PlatformCanvas.cs#L644 _fillImage is already released and null.

Steps to Reproduce

  1. Go to Maui samples
  2. open GraphicsViewDemos
  3. open Image paint demo page

Should render downsized bot image (as on Android), instead it crashes (image is drawn, but app crashes due to null pointer)

Link to public reproduction project repository

https://github.com/dotnet/maui-samples/issues/336

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

Mac OS 14, iOS 15

Did you find any workaround?

no

Relevant log output

https://github.com/dotnet/maui-samples/issues/336#issuecomment-1873323734
XamlTest commented 9 months ago

Verified this on Visual Studio Enterprise 17.9.0 Preview 4(8.0.3). Project: GraphicsViewDemos.zip

iOS 17.2 and MacCatalyst: Throws exception: System.NullReferenceException.

Windows: Image does not render. image Android: Works well.

Screenshot 2024-01-31 at 11 26 10 AM