From c0a7f06ee4540c98f302373d39b9de095e328945 Mon Sep 17 00:00:00 2001 From: Andoni Morales Alastruey Date: Tue, 10 Aug 2021 17:17:11 +0200 Subject: [PATCH] Fix ownership of returned Opaque with GetOpaque GetOpaque is returning Opaque objects with owner set to the opposite value as the one requested. This behaviour can be seen when overridingon virtual methods like BaseSink.OnQuery that have has parameters Gst.MiniObject's and where GetOpaque is called with owned=false. The new Query object is owned and with an extra Ref, making it IsWritable=false, while it should be !owned and with refcount of 1 make it IsWritable=false --- Source/glib/Opaque.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/glib/Opaque.cs b/Source/glib/Opaque.cs index 2955ae8b0..664d5545e 100644 --- a/Source/glib/Opaque.cs +++ b/Source/glib/Opaque.cs @@ -39,18 +39,19 @@ public static Opaque GetOpaque (IntPtr o, Type type, bool owned) return null; Opaque opaque = (Opaque)Activator.CreateInstance (type, new object[] { o }); - if (owned) { - if (opaque.owned) { + if (opaque.owned) { // The constructor took a Ref it shouldn't have, so undo it opaque.Unref (o); - } + } + if (owned) { opaque.owned = true; - } else + } else { opaque = opaque.Copy (o); + } return opaque; } - + public Opaque () { owned = true;