[Mono-list] GdiPlus NullReferenceException

Yury Serdyuk YSerdyuk@4ds.com
Wed, 16 Feb 2005 10:40:19 +0300


Hi !

NullReferenceException is thrown when trying to launch GDI application which 
uses a lot of threads :


using System;
using System.Threading;
using System.Drawing;

public class TestGDIPlus  {
 public static void Main( string[] args ) {
  int nThreads = int.Parse( args [0] );
  
  for ( int i = 0; i < nThreads; i++ ) {
   Thread t = new Thread( new ThreadStart( TestGDIPlus.Run ) );
   t.Start();
  }
 }

 public static void Run() {
  Bitmap bmp = new Bitmap ( 1000, 1000, 
                  System.Drawing.Imaging.PixelFormat.Format32bppArgb );
 }
}

We run it as


mono /path/to/TestGDIPlus.exe 8


Actual Results:
It throws this exception for each thread

Unhandled Exception: System.NullReferenceException: Object reference not 
set to an instance of an object
in (unmanaged) (wrapper managed-to-native) 
System.Drawing.GDIPlus:GdipCreateBitmapFromScan0 
(int,int,int,System.Drawing.Imaging.PixelFormat,intptr,intptr&)
in <0x00004> (wrapper managed-to-native) 
System.Drawing.GDIPlus:GdipCreateBitmapFromScan0 
(int,int,int,System.Drawing.Imaging.PixelFormat,intptr,intptr&)
in <0x00058> System.Drawing.Bitmap:.ctor 
(int,int,System.Drawing.Imaging.PixelFormat)
in <0x0006f> (wrapper remoting-invoke-with-check) 
System.Drawing.Bitmap:.ctor (int,int,System.Drawing.Imaging.PixelFormat)
in <0x00036> TestGDIPlus:Run ()
in <0x0005f> (wrapper delegate-invoke) 
System.MulticastDelegate:invoke_void ()

or this one
[serdyuk@itk-104 tmp]$ mono TestGDIPlus.exe 8

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
in (unmanaged) System.Drawing.Bitmap:.ctor (int,int,System.Drawing.Imaging.PixelFormat)

This failure is occured only occasionally,
so one needs to try run program multiply ones,
as 

> [serdyuk@itk-104 tmp]$ mono TestGDIPlus.exe 8 [serdyuk@itk-104 tmp]$ 
> mono TestGDIPlus.exe 8 [serdyuk@itk-104 tmp]$ mono TestGDIPlus.exe 8 
> [serdyuk@itk-104 tmp]$ mono TestGDIPlus.exe 8 [serdyuk@itk-104 tmp]$ 
> mono TestGDIPlus.exe 8 Unhandled Exception: 
> System.NullReferenceException: Object reference not set to an instance 
> of an object in (unmanaged) System.Drawing.Bitmap:.ctor 
> (int,int,System.Drawing.Imaging.PixelFormat) [serdyuk@itk-104 tmp]$


We have tested under Mono 1.0.5 ( libgdiplus-1.0.5 ) and
Mono 1.1.3 ( libgdiplus-1.1.3 ) with the same result.
We have used two diffrent glib-2.0 libraries -

2.2.1 and  2.4.7 .

Please, help.

Thanks.

Yury Serdyuk.