microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.2k stars 669 forks source link

WriteableBitmap throws an exception when accessing PixelBuffer #9533

Open gmgallo opened 3 months ago

gmgallo commented 3 months ago

Describe the bug

Following the code example the WriteableBitmap is not properly costructed. PixelBuffer is null after construction. This is the control inspetion in Visual Studio after creation:

image

Steps to reproduce the bug

    var renderTarget = new WriteableBitmap(2048, 1024);

    // renderTarget is not null here, but next line throws an exeption
    var buf = renderTarget.PixelBuffer;

Expected behavior

As in the example here WriteableBitmap.PixelBuffer property

Screenshots

No response

NuGet package version

Windows App SDK 1.5.1: 1.5.240311000

Packaging type

Packaged (MSIX)

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022-preview

Additional context

No response

codendone commented 3 months ago

I don't repro this issue. Is this issue affecting how your app code runs, or just Visual Studio's object visualizer when debugging?

gmgallo commented 3 months ago

The error throws at runtime, all looks good in the editor. There is no other code between the two lines of code shown. The screenshot shows the object inspection with a breakpoint on the line var buf = .... I'll try on an empty application.

kmahone commented 3 months ago

I was also unable to reproduce this issue. @gmgallo do you hit this in a blank app?

gmgallo commented 3 months ago

No, I haven't tested in a blank app yet. I have to move on and don't have time to investigate.

I suspect that Visual Stuido is the one to blame, not this assembly. Strange things happen all the time, like this error is happening to me now. Xaml Hot-Reload not working on and off on the same project, and the list goes on and on,