From 9713ead713201f10c0fe4185bc8bb0df4c276cc3 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Mon, 23 Aug 2010 10:54:41 +0200 Subject: [PATCH] Don't modify hash tables while iterating over them This caused crashes for caps with more than a single struct when unreffing them in one way or another. Fixes bug #627677. --- gstreamer-sharp/Caps.custom | 3 ++- tests/CapsTest.cs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gstreamer-sharp/Caps.custom b/gstreamer-sharp/Caps.custom index de2e2554be..4ff992ded9 100644 --- a/gstreamer-sharp/Caps.custom +++ b/gstreamer-sharp/Caps.custom @@ -57,8 +57,9 @@ private void RemoveStructureReference (Structure s) { private void RemoveStructureReferences () { foreach (Structure s in structures.Values) { - RemoveStructureReference (s); + s.CreateNativeCopy (); } + structures.Clear (); } [DllImport ("libgstreamer-0.10.dll") ] diff --git a/tests/CapsTest.cs b/tests/CapsTest.cs index 826098c7b2..f0e25a4ebc 100644 --- a/tests/CapsTest.cs +++ b/tests/CapsTest.cs @@ -10,6 +10,7 @@ using System; using NUnit.Framework; using Gst; +using Gst.Video; [TestFixture] public class CapsTest { @@ -91,4 +92,16 @@ public class CapsTest { "height=(int)480"); Assert.IsTrue (caps3.IsEqual (caps4)); } + + [Test] + public void TestManagedReferences() { + Caps tmp = VideoUtil.FormatToTemplateCaps(Gst.Video.VideoFormat.RGBX); + Caps caps = tmp.Copy(); + caps[0]["width"] = 640; + caps[0]["height"] = 480; + + caps.Append(tmp); + Caps any = Caps.NewAny(); + caps.Merge(any); + } }