Skip to content

Icon.ToBitmap() crashes on linux (likely a gdiplus error) #46

Description

@mfeemster

OS: linux mint
Version: latest
.NET: 9

Creating an icon, then attempting to get its bitmap exits with an out of memory exception. I've traced the crash to Image.InitializeFromStream()

int st = Gdip.GdipLoadImageFromDelegate_linux() is called and the return value is checked with:
Gdip.CheckStatus(st);

That last line throws because instead of st having a value of 0, it has a value of 3.

Upon inspecting the icon loading code here @madewokherd :
https://gitlab.winehq.org/mono/libgdiplus/-/blob/main/src/bitmap.c?ref_type=heads
https://gitlab.winehq.org/mono/libgdiplus/-/blob/main/src/icocodec.c?ref_type=heads

It appears the default return value is out of memory for many different operations.

To test, I found an internal method in Icon.Unix.cs named BuildBitmapOnWin32() and made it public just to see what would happen.

var ico = new System.Drawing.Icon("./Icon1.ico");

var bmp1 = ico.ToBitmap();//Crashes
var bmp2 = ico.BuildBitmapOnWin32();//Ok

Note that with regular .NET 9 on windows, this code runs fine.

github disallows attachments of icon files, but you can download the icon that is giving me trouble here:
https://bitbucket.org/mfeemster/keysharp/src/master/Keysharp.Tests/Code/Gui/Icon1.ico

Any help is much appreciated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions