mono / mono

Mono open source ECMA CLI, C# and .NET implementation.
https://www.mono-project.com
Other
10.94k stars 3.81k forks source link

System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter] #13049

Open bskimaa opened 5 years ago

bskimaa commented 5 years ago

Steps to Reproduce

  1. apt-get install mono-complete <---- install mono
  2. vi hellowin.cs <---- edit a cs file using System; using System.Drawing; using System.Windows.Forms;

public class HelloWorld : Form { static public void Main () { Application.Run (new HelloWorld ()); }

public HelloWorld ()
{
    Button b = new Button ();
    b.Text = "Click Me!";
    b.Click += new EventHandler (Button_Click);
    Controls.Add (b);
}
private void Button_Click (object sender, EventArgs e)
{
    MessageBox.Show ("Button Clicked!");
}

}

  1. csc hellowin.cs -r:System.Windows.Forms.dll <--- compile
  2. mono ./hellowin.exe <--- run

Current Behavior

Expected Behavior

On which platforms did you notice this

[ ] macOS [*] Linux :

uname -a

    Linux  xxxxx 4.14.73 #1 SMP PREEMPT Thu Feb 14 14:03:40 UTC 2019 armv7l GNU/Linux
    # lsb_release -a
   No LSB modules are available.
   Distributor ID: Debian
   Description:    Debian GNU/Linux 9.8 (stretch)
   Release:        9.8
   Codename:       stretch

[ ] Windows

Version Used:

Mono JIT compiler version 5.18.0.240 (tarball Wed Jan 16 09:28:29 UTC 2019) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: normal Notifications: epoll Architecture: armel,vfp+hard Disabled: none Misc: softdebug Interpreter: yes LLVM: yes(600) Suspend: preemptive GC: sgen (concurrent by default)

Stacktrace

Please paste the stack trace here if available.

root@unibest:~/wk# mono ./hellowin.exe

Unhandled Exception:
System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) [0x00098] in <2bb3052119444fb7807d658e27511cb1>:0
  at System.Drawing.Bitmap..ctor (System.Int32 width, System.Int32 height, System.Drawing.Imaging.PixelFormat format) [0x00016] in <2bb3052119444fb7807d658e27511cb1>:0
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, System.Int32 width, System.Int32 height) [0x00000] in <2bb3052119444fb7807d658e27511cb1>:0
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, System.Drawing.Size newSize) [0x00010] in <2bb3052119444fb7807d658e27511cb1>:0
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap..ctor(System.Drawing.Image,System.Drawing.Size)
  at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, System.Drawing.Color cursor_pixel, System.Drawing.Color mask_pixel, System.Int32 xHotSpot, System.Int32 yHotSpot) [0x00045] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, System.Drawing.Color cursor_pixel, System.Drawing.Color mask_pixel, System.Int32 xHotSpot, System.Int32 yHotSpot) [0x00000] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) [0x00058] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) [0x0001e] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Cursors.get_SizeNWSE () [0x00014] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) [0x00006] in <895eff5fc3c3440985711e3d9bfab833>:0
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip..ctor(System.Windows.Forms.Control)
  at System.Windows.Forms.ScrollableControl.CreateScrollbars () [0x000c2] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.ScrollableControl..ctor () [0x000b0] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Form..ctor () [0x00012] in <895eff5fc3c3440985711e3d9bfab833>:0
  at HelloWorld..ctor () [0x00000] in <57fd24932edb46d1aa81f5f57cbd9c3f>:0
  at (wrapper remoting-invoke-with-check) HelloWorld..ctor()
  at HelloWorld.Main () [0x00001] in <57fd24932edb46d1aa81f5f57cbd9c3f>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) [0x00098] in <2bb3052119444fb7807d658e27511cb1>:0
  at System.Drawing.Bitmap..ctor (System.Int32 width, System.Int32 height, System.Drawing.Imaging.PixelFormat format) [0x00016] in <2bb3052119444fb7807d658e27511cb1>:0
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, System.Int32 width, System.Int32 height) [0x00000] in <2bb3052119444fb7807d658e27511cb1>:0
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, System.Drawing.Size newSize) [0x00010] in <2bb3052119444fb7807d658e27511cb1>:0
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap..ctor(System.Drawing.Image,System.Drawing.Size)
  at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, System.Drawing.Color cursor_pixel, System.Drawing.Color mask_pixel, System.Int32 xHotSpot, System.Int32 yHotSpot) [0x00045] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, System.Drawing.Color cursor_pixel, System.Drawing.Color mask_pixel, System.Int32 xHotSpot, System.Int32 yHotSpot) [0x00000] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) [0x00058] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) [0x0001e] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Cursors.get_SizeNWSE () [0x00014] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) [0x00006] in <895eff5fc3c3440985711e3d9bfab833>:0
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip..ctor(System.Windows.Forms.Control)
  at System.Windows.Forms.ScrollableControl.CreateScrollbars () [0x000c2] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.ScrollableControl..ctor () [0x000b0] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <895eff5fc3c3440985711e3d9bfab833>:0
  at System.Windows.Forms.Form..ctor () [0x00012] in <895eff5fc3c3440985711e3d9bfab833>:0
  at HelloWorld..ctor () [0x00000] in <57fd24932edb46d1aa81f5f57cbd9c3f>:0
  at (wrapper remoting-invoke-with-check) HelloWorld..ctor()
  at HelloWorld.Main () [0x00001] in <57fd24932edb46d1aa81f5f57cbd9c3f>:0
flaviut commented 5 years ago

Quite a few people are also running into this issue:

flaviut commented 5 years ago

@bskimaa can you please re-open this issue? It is still valid and still needs a fix.

Clodo76 commented 5 years ago

I reproduce it also on a Linux Mint 19 Tara, with Mono version 5.16.0.220. An interesting link: https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/1246872

Maybe it's possible to call from mono (via DllImport) the suggested "xf86_cursors_init(screen, 64,64,0)" as workaround?

I absolutely need a workaround to this, that works with any recent Mono distribution (i distribute my app in .deb package with Mono as dependencies). I offer 200$ via Paypal for any workaround that can be applied to the code of @bskimaa. Thanks.

mickeyjf commented 5 years ago

It was several years back and probably no longer relevant, but when we first started working with the BB there were two flavors, armhf Mono and not-hard float. We had to patch to get a working mono for hard float, and until then there were several arithmetic related bugs that we encountered. Dates was one, if I recall. Screen resolution calculations could have been another.

Clodo76 commented 5 years ago

Linux Mint 19 Tara upgraded to Mono version 5.18.1.3, resolved. I tested the following distro in a fresh install:

In all,

All works, i cannot reproduce anymore.

sbiglia commented 4 years ago

I'm having this exact same issue on a Parrot OS linux installation on a vultr.com VPS. I managed to solve it by patching DefineCursor method in XPlatUIX11.cs file from mono sources an then recompiling.

DefineCursor method has this code: `if (XQueryBestCursor(DisplayHandle, RootWindow, bitmap.Width, bitmap.Height, out width, out height) == 0) { return IntPtr.Zero; }

        // Win32 only allows creation cursors of a certain size
        if ((bitmap.Width != width) || (bitmap.Width != height)) {
            cursor_bitmap = new Bitmap(bitmap, new Size(width, height));
            cursor_mask = new Bitmap(mask, new Size(width, height));
        } else {
            cursor_bitmap = bitmap;
            cursor_mask = mask;
        }`

It seems that XQueryBestCursor function return width=0 and height=0, and after that, creating a new Bitmap with those values throws an exception.

Just added a small if before creating the Bitmap, setting a width and height default value in case they where 0, that got rid of the crash, and now my small app runs smoothly.

Forgot to mention: my actual mono version is 5.20.1.34, but the code in DefineCursor method is still the same on the last mono source from git, so i think this bug is still there.

linhz0hz commented 7 months ago

This happens on two of my SBCs running latest armbian. However with some stock images from respective board vendors it was fine. Also, if I run this with X-forwarding through SSH, it also runs fine.

mirh commented 1 month ago

Ladies and gents, I could solve my problem with keepass crashing in most menus by recompiling libgdiplus with the --with-pango switch.

Vkurtke commented 1 month ago

I have this problem. My HelloWorld doesn't work on Astra Linux via Hyper-V but works fine on Windows and other PC with Astra Linux where Virtual machine is not used.

sancheolz commented 1 month ago

@Vkurtke, run your app with debug mono --debug MyApp.exe Now you can see stacktraces with line numbers. You nedd to modify code to add Console.WriteLine for last call params. Than build modified project like here https://github.com/mono/mono/issues/20769#issuecomment-2144648092