From 1840bd7ef1f48febcf7bc097954230a83b602ff7 Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Wed, 9 Apr 2003 17:50:51 +0000 Subject: [PATCH] 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. svn path=/trunk/gtk-sharp/; revision=13450 --- ChangeLog | 8 ++++++++ glib/Object.cs | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) 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); }