Skip to content

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

@peterblazejewicz

Description

@peterblazejewicz

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:

var platformWrapper = _fillImage.ToPlatformImage() as PlatformImage;

_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

dotnet/maui-samples#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions