Issue with BitmapEncoder and BitmapDecoder in Windows.Graphics.Imaging

tomohak 0 Reputation points
2024-09-03T08:19:11.34+00:00

Hi everyone,

I'm encountering an error while working with the Windows.Graphics.Imaging namespace. Here's the relevant code snippet:

using (Windows.Storage.Streams.InMemoryRandomAccessStream stream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
{
    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(
        BitmapEncoder.BmpEncoderId, stream);
    encoder.SetSoftwareBitmap(softwareBitmap);

    await encoder.FlushAsync();

    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
    return await decoder.GetSoftwareBitmapAsync(
        softwareBitmap.BitmapPixelFormat,
        BitmapAlphaMode.Premultiplied,
        new BitmapTransform { Rotation = BitmapRotation.Clockwise90Degrees, ...},...);
}

Error details:

  • Message: invalid_pointer_read_c0000005_windows.graphics.dll!windows::graphics::imaging::ccreateencoderoperation::getresults
  • Stack trace:

0 coreclr.dll EEPolicy::HandleFatalError 0x000000000000007D

1 coreclr.dll ProcessCLRException 0x000000000010A1CF

2 ntdll.dll RtlpExecuteHandlerForException 0x000000000000000F

3 ntdll.dll RtlDispatchException 0x0000000000000286

4 ntdll.dll KiUserExceptionDispatch 0x000000000000002E

5 Windows.Graphics.dll Windows::Graphics::Imaging::CCreateEncoderOperation::GetResults 0x000000000000007B

6 unknown.dll null 0x0000000000000000

7 unknown.dll null 0x0000000000000000

8 coreclr.dll PrestubWorkerEnd_V1 0x0000000000000000

9 unknown.dll null 0x0000000000000000

10 unknown.dll null 0x0000000000000000

11 unknown.dll noop 0x0000000000000000

12 unknown.dll null 0x0000000000000000

13 coreclr.dll vtable_InlinedCallFrame 0x0000000000000000

14 unknown.dll null 0x0000000000000000

I've already checked the following:

  • The "softwareBitmap" object is properly initialized.
  • The problem cannot be replicated in the development environment but occurs in certain users' environments.

Any insights or suggestions on how to troubleshoot this issue would be greatly appreciated!

Thanks in advance.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
791 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,578 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.