Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Source/glib/Opaque.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Opaque : IWrapper, IDisposable {

IntPtr _obj;
bool owned;
bool disposing;
bool setOwnedRecursionGuard;

public static Opaque GetOpaque (IntPtr o, Type type, bool owned)
{
Expand All @@ -42,7 +44,9 @@ public static Opaque GetOpaque (IntPtr o, Type type, bool owned)
if (owned) {
if (opaque.owned) {
// The constructor took a Ref it shouldn't have, so undo it
opaque.setOwnedRecursionGuard = true;
opaque.Unref (o);
opaque.setOwnedRecursionGuard = false;
}
opaque.owned = true;
} else
Expand Down Expand Up @@ -85,6 +89,7 @@ protected IntPtr Raw {

public virtual void Dispose ()
{
disposing = true;
Raw = IntPtr.Zero;
GC.SuppressFinalize (this);
}
Expand Down Expand Up @@ -119,6 +124,14 @@ public bool Owned {
return owned;
}
set {
// unref if Owned is set to false without disposing this object
if (setOwnedRecursionGuard) return;
if (owned && !value && _obj != IntPtr.Zero && !disposing) {
setOwnedRecursionGuard = true;
this.Unref(_obj);
setOwnedRecursionGuard = false;
}

owned = value;
}
}
Expand Down