diff --git a/ChangeLog b/ChangeLog index 37786b4a5..8c2faf898 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-04-09 Gonzalo Paniagua Javier + + * glib/Object.cs: + (GetObject): check that the target of the WeakReference is still there. Otherwise, + create a new wrapper for the IntPtr. + + This fixes the random nullrefs when running nunit-gtk. + 2003-04-03 Gonzalo Paniagua Javier * generator/CallbackGen.cs: the new generated wrappers have: diff --git a/glib/Object.cs b/glib/Object.cs index a1adeacf7..fad5054d7 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -163,8 +163,15 @@ namespace GLib { public static Object GetObject(IntPtr o) { WeakReference obj = Objects[o] as WeakReference; - if (obj != null) - return obj.Target as GLib.Object; + if (obj != null) { + // If the target object has not been collected, use it... + if (obj.IsAlive) + return obj.Target as GLib.Object; + + // ... otherwise we create a new wrapper around the IntPtr. + Objects [o] = null; + } + return GtkSharp.ObjectManager.CreateObject(o); }