[Gtk-sharp-list] Invalid IL code complain on access of Gdk.Pixbuf

Sebastian scut@nb.in-berlin.de
Mon, 26 May 2003 16:36:01 +0200


--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hi,


I use Alp's debian mono 0.24 packages (gtk-sharp 0.8).

The attached program was compiled with:
mcs --unsafe SelPixbuf.cs -r gtk-sharp -r gdk-sharp

(It loads an image file "image.png" using Gdk.Pixbuf and tries to access its
 raw red/green/blue elements).

I get the following output:

$ ./SelPixbuf.exe 

** ERROR **: Invalid IL code at IL004a in 00 .SelPixbuf:get_Brightness ():
IL_004a: mul       


aborting...
Aborted
$

The disassembly and the binary is attached. I first thought it may be a
direct result of using the unsafe {} block, but this looks like mcs
generates invalid code. (There was a bug in mcs 0.23 that did generate
invalid IL code, but that was fixed, wasn't it?).

Also, mint 0.24 chews:

$ mint SelPixbuf.exe 

** ERROR **: file class.c: line 1732 (mono_class_get_field): assertion
failed: (mono_metadata_token_code (field_token) == MONO_TOKEN_FIELD_DEF)
aborting...
Aborted
$


Can anyone give me an advice how to work around this? (Or how I can help
tracking this down?)


ciao,
Sebastian

-- 
-. scut@nb.in-berlin.de -. + http://segfault.net/~scut/ `--------------------.
-' segfault.net/~scut/pgp `' 5453 AC95 1E02 FDA7 50D2 A42D 427E 6DEF 745A 8E07
`- W88 heads sold. 4 payloads ready, payment due. hi echelon! ---------------'

--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="SelPixbuf.cs"


using System;
using Gtk;
using GtkSharp;
using Gdk;

/// <summary>
/// Managed image class. Allow convenient access to parts of an image
/// (tilezation) and various preprocessing steps. The methods in this class
/// make heavy usage of the <see cref="Gdk.Pixbuf">GDK Pixbuf</see> class.
/// </summary>
class SelPixbuf
{
	Pixbuf pix;
	Pixdata pd;

	SelPixbuf (string filename)
	{
		pix = new Pixbuf (filename);
		pd = new Pixdata ();
		pd.FromPixbuf (pix, false);

		if ((PixdataType) pd.pixdata_type != (PixdataType.ColorTypeRgb |
			PixdataType.SampleWidth8 | PixdataType.EncodingRaw))
		{
			Console.WriteLine ("invalid format");
			// TODO: throw custom exception
		}
	}

	public double Brightness {
		get {
			double max = 0.0;

			for (int y = 0 ; y < pd.height ; ++y) {
				for (int x = 0 ; x < pd.width ; ++x) {
					IntPtr pixdata = pd._pixel_data;
					int red, green, blue;

					unsafe {
						char * direct = (char *) pixdata;
						red = direct[y * pd.width * 3 + x * 3 + 0];
						green = direct[y * pd.width * 3 + x * 3 + 1];
						blue = direct[y * pd.width * 3 + x * 3 + 2];
					}
					Console.WriteLine ("{0}", red);
				}
			}
			// TODO: calculate real brightness
			return (1.0);
		}
	}

	public static void Main ()
	{
		Application.Init ();
		SelPixbuf spb = new SelPixbuf ("image.png");
		Console.WriteLine ("Brightness = {0}", spb.Brightness);
	}
}



--VS++wcV0S1rZb1Fb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="SelPixbuf.dis"

.assembly extern mscorlib
{
  .ver 1:0:3300:0
}
.assembly extern gdk-sharp
{
  .ver 0:0:0:0
}
.assembly extern gtk-sharp
{
  .ver 0:0:0:0
}
.assembly 'SelPixbuf'
{
  .hash algorithm 0x00008004
  .ver  0:0:0:0
}
  .class private auto ansi beforefieldinit SelPixbuf
  	extends [mscorlib]System.Object
  {
    .field  private   class [gdk-sharp]Gdk.Pixbuf pix
    .field  private   valuetype [gdk-sharp]Gdk.Pixdata pd

    // method line 1
    .method private hidebysig  specialname  rtspecialname 
           instance default void .ctor(string filename)  cil managed 
    {
        // Method begins at RVA 0x20ec
	// Code size 81 (0x51)
	.maxstack 6
	IL_0000: ldarg.0 
	IL_0001: call instance void valuetype [corlib]System.Object::.ctor()
	IL_0006: ldarg.0 
	IL_0007: ldarg.1 
	IL_0008: newobj instance void class [gdk-sharp]Gdk.Pixbuf::.ctor(string)
	IL_000d: stfld  class [gdk-sharp]Gdk.Pixbuf SelPixbuf::pix
	IL_0012: ldarg.0 
	IL_0013: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_0018: initobj [gdk-sharp]Gdk.Pixdata
	IL_001e: ldarg.0 
	IL_001f: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_0024: ldarg.0 
	IL_0025: ldfld  class [gdk-sharp]Gdk.Pixbuf SelPixbuf::pix
	IL_002a: ldc.i4.0 
	IL_002b: call instance native int valuetype [gdk-sharp]Gdk.Pixdata::FromPixbuf(class [gdk-sharp]Gdk.Pixbuf, bool)
	IL_0030: pop 
	IL_0031: ldarg.0 
	IL_0032: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_0037: ldfld fieldref-0x0a000004
	IL_003c: ldc.i4 16842753
	IL_0041: beq IL_0050

	IL_0046: ldstr "invalid format"
	IL_004b: call void class [corlib]System.Console::WriteLine(string)
	IL_0050: ret 
    } // end of method SelPixbuf::instance default void .ctor(string filename) 

    // method line 2
    .method public static 
           default void Main()  cil managed 
    {
        // Method begins at RVA 0x2149
	.entrypoint
	// Code size 38 (0x26)
	.maxstack 6
	.locals init (
		class SelPixbuf	V_0)
	IL_0000: call void class [gtk-sharp]Gtk.Application::Init()
	IL_0005: ldstr "image.png"
	IL_000a: newobj instance void class SelPixbuf::.ctor(string)
	IL_000f: stloc.0 
	IL_0010: ldstr "Brightness = {0}"
	IL_0015: ldloc.0 
	IL_0016: callvirt instance float64 class SelPixbuf::get_Brightness()
	IL_001b: box [mscorlib]System.Double
	IL_0020: call void class [corlib]System.Console::WriteLine(string, object)
	IL_0025: ret 
    } // end of method SelPixbuf::default void Main() 

    // method line 3
    .method public hidebysig  specialname 
           instance default float64 get_Brightness()  cil managed 
    {
        // Method begins at RVA 0x217b
	// Code size 230 (0xe6)
	.maxstack 6
	.locals init (
		float64	V_0,
		int32	V_1,
		int32	V_2,
		native int	V_3,
		int32	V_4,
		int32	V_5,
		int32	V_6,
		char*	V_7,
		int32	V_8,
		int32	V_9)
	IL_0000: ldc.r8 0
	IL_0009: stloc.0 
	IL_000a: ldc.i4.0 
	IL_000b: stloc.1 
	IL_000c: br IL_00c9

	IL_0011: ldc.i4.0 
	IL_0012: stloc.2 
	IL_0013: br IL_00ae

	IL_0018: ldarg.0 
	IL_0019: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_001e: ldfld fieldref-0x0a000008
	IL_0023: stloc.3 
	IL_0024: ldloc.3 
	IL_0025: call void* valuetype [corlib]System.IntPtr::op_Explicit(native int)
	IL_002a: stloc.s 7
	IL_002c: ldloc.s 7
	IL_002e: conv.i 
	IL_002f: ldloc.1 
	IL_0030: conv.i8 
	IL_0031: ldarg.0 
	IL_0032: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_0037: ldfld fieldref-0x0a00000a
	IL_003c: conv.u8 
	IL_003d: mul 
	IL_003e: ldc.i4.3 
	IL_003f: conv.i8 
	IL_0040: mul 
	IL_0041: ldloc.2 
	IL_0042: ldc.i4.3 
	IL_0043: mul 
	IL_0044: conv.i8 
	IL_0045: add 
	IL_0046: ldc.i4.0 
	IL_0047: conv.i8 
	IL_0048: add 
	IL_0049: ldc.i4.2 
	IL_004a: mul 
	IL_004b: add 
	IL_004c: ldind.u2 
	IL_004d: stloc.s 4
	IL_004f: ldloc.s 7
	IL_0051: conv.i 
	IL_0052: ldloc.1 
	IL_0053: conv.i8 
	IL_0054: ldarg.0 
	IL_0055: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_005a: ldfld fieldref-0x0a00000a
	IL_005f: conv.u8 
	IL_0060: mul 
	IL_0061: ldc.i4.3 
	IL_0062: conv.i8 
	IL_0063: mul 
	IL_0064: ldloc.2 
	IL_0065: ldc.i4.3 
	IL_0066: mul 
	IL_0067: conv.i8 
	IL_0068: add 
	IL_0069: ldc.i4.1 
	IL_006a: conv.i8 
	IL_006b: add 
	IL_006c: ldc.i4.2 
	IL_006d: mul 
	IL_006e: add 
	IL_006f: ldind.u2 
	IL_0070: stloc.s 5
	IL_0072: ldloc.s 7
	IL_0074: conv.i 
	IL_0075: ldloc.1 
	IL_0076: conv.i8 
	IL_0077: ldarg.0 
	IL_0078: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_007d: ldfld fieldref-0x0a00000a
	IL_0082: conv.u8 
	IL_0083: mul 
	IL_0084: ldc.i4.3 
	IL_0085: conv.i8 
	IL_0086: mul 
	IL_0087: ldloc.2 
	IL_0088: ldc.i4.3 
	IL_0089: mul 
	IL_008a: conv.i8 
	IL_008b: add 
	IL_008c: ldc.i4.2 
	IL_008d: conv.i8 
	IL_008e: add 
	IL_008f: ldc.i4.2 
	IL_0090: mul 
	IL_0091: add 
	IL_0092: ldind.u2 
	IL_0093: stloc.s 6
	IL_0095: ldstr "{0}"
	IL_009a: ldloc.s 4
	IL_009c: box [mscorlib]System.Int32
	IL_00a1: call void class [corlib]System.Console::WriteLine(string, object)
	IL_00a6: ldloc.2 
	IL_00a7: ldc.i4.1 
	IL_00a8: add 
	IL_00a9: stloc.s 8
	IL_00ab: ldloc.s 8
	IL_00ad: stloc.2 
	IL_00ae: ldloc.2 
	IL_00af: conv.i8 
	IL_00b0: ldarg.0 
	IL_00b1: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_00b6: ldfld fieldref-0x0a00000a
	IL_00bb: conv.u8 
	IL_00bc: blt IL_0018

	IL_00c1: ldloc.1 
	IL_00c2: ldc.i4.1 
	IL_00c3: add 
	IL_00c4: stloc.s 9
	IL_00c6: ldloc.s 9
	IL_00c8: stloc.1 
	IL_00c9: ldloc.1 
	IL_00ca: conv.i8 
	IL_00cb: ldarg.0 
	IL_00cc: ldflda  valuetype [gdk-sharp]Gdk.Pixdata SelPixbuf::pd
	IL_00d1: ldfld fieldref-0x0a00000b
	IL_00d6: conv.u8 
	IL_00d7: blt IL_0011

	IL_00dc: ldc.r8 1
	IL_00e5: ret 
    } // end of method SelPixbuf::instance default float64 get_Brightness() 

	.property special runtime float64 Brightness ()
	{
		.get instance default float64 get_Brightness() 
	}
  } // end of type SelPixbuf


--VS++wcV0S1rZb1Fb
Content-Type: application/x-msdos-program
Content-Disposition: attachment; filename="SelPixbuf.exe"
Content-Transfer-Encoding: base64

TVoAAAYAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4g
RE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAECAAMl0j4AAAAAAAAAAOAADgELAQYAAAgAAAAA
AAAAAAAAACAAAAAgAAAAAAAAAABAAAAgAAAAAgAABAAAAAAAAAAEAAAAAAAAAABgAAAAAgAA
AAAAAAMAAAAAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAABggAABPAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAEAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAQIAAACAAAAAAAAAAAAAAAZCAAAEgAAAAAAAAAAAAAAC50
ZXh0AAAAhAYAAAAgAAAACAAAAAIAAAAAAAAAAAAAAAAAACAAAGAucmVsb2MAAAwAAAAAQAAA
AAIAAAAKAAAAAAAAAAAAAAAAAABAAABCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/JRAgQAAAAAAAAAAAAAAAQiAAAAAAAABaIAAA
AAAAAAAAAABOIAAAECAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABfQ29yRXhlTWFpbgBtc2Nv
cmVlLmRsbABAIAAAAAAAAAAASAAAAAIAAABwIgAAFAQAAAEAAAACAAAGcCIAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA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