[Gtk-sharp-list] System.InvalidCastException

Paulo Pires paulo.pires@vodafone.pt
Tue, 15 Mar 2005 15:07:11 +0000


Hi again

According to jonp @ irc.us.gimp.org, this is a known bug where the
probable problem is that once I'm relying on the CanvasGroup to maintain
a reference to my object, and the GC can't see it, GC will simply
collect it although it's held by GTK+.

AFAIL this isn't in bugzilla, but I and jonp hope that this would be fix
in GTK# 2.0


Thanks a lot jonp,
Paulo Pires


Ter, 2005-03-15 =E0s 14:43 +0000, Paulo Pires escreveu:
>Hi list
>
>this seems odd!
>
>I'm still working around my Canvas, and what I couldn't do with
>CanvasWidget, I'm doing with CanvasGroup. So, I've created an object,
>wdgSemaphore, which derives from Gnome.CanvasGroup. So far, so good.
>
>The problem appears when I handle my Canvas.CanvasEvent with the
>following code:
><code>
>
>private void OnCanvasEvent(object o, Gnome.CanvasEventArgs args)
>	{
>		Gdk.EventButton ev =3D new Gdk.EventButton (args.Event.Handle);
>	=09
>		Globals.LogLn("Type -> " + o.GetType());
>	=09
>		//Gnome.CanvasGroup item =3D (Gnome.CanvasGroup) o;
>		wdgSemaphore item =3D (wdgSemaphore) o;
>	=09
>		Globals.LogLn("-> " + ev.Type);
>	=09
>		switch (ev.Type)
>		{
>			case Gdk.EventType.ButtonPress:
>				if (ev.Button =3D=3D 1) {
>					remember_x =3D ev.X;
>					remember_y =3D ev.Y;
>				} else if (ev.Button =3D=3D 3) {
>					// destroy item and subsequent semaphore
>					WorldToUI.RemoveSemaphore(item);
>				}
>				break;
>			=09
>			case Gdk.EventType.MotionNotify:
>				Gdk.ModifierType state =3D (Gdk.ModifierType) ev.State;
>				if ((state & Gdk.ModifierType.Button1Mask) !=3D 0)
>				{
>					double new_x =3D ev.X, new_y =3D ev.Y;
>					item.Move (new_x - remember_x, new_y - remember_y);
>					remember_x =3D new_x;
>					remember_y =3D new_y;
>				}
>				break;
>			=09
>			case Gdk.EventType.EnterNotify:
>				break;
>			=09
>			case Gdk.EventType.LeaveNotify:
>				break;
>		}
>	}
>
></code>
>
>That Global.LogLn, is outputting the type of o and then the
>Gdk.Event.Type, and here it follows:
>
>(...)
>
>Type -> TrafficMan.wdgSemaphore
>-> MotionNotify
>Type -> TrafficMan.wdgSemaphore
>-> MotionNotify
>Type -> TrafficMan.wdgSemaphore
>-> MotionNotify
>Type -> TrafficMan.wdgSemaphore
>-> LeaveNotify
>Type -> Gnome.CanvasGroup
>
>Unhandled Exception: System.InvalidCastException: Cannot cast from
>source type to destination type.
>
>(...)
>
>What the hell is going on so that the type is changed on the Event?!
>
>Hugs
>Paulo Pires
>
>_______________________________________________
>Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/gtk-sharp-list