From ede4562c23ac6405e1f9190aa8c3de0016d8c806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 27 May 2009 14:56:42 +0200 Subject: [PATCH] Prevent that the GC frees the native GstIterator too early The native GstIterator is freed once the Gst.Enumerable instance is destroyed. At this point there could still be a Gst.Enumerator instance that uses the native GstIterator and would crash then. Store the Gst.Enumerable instance inside the Gst.Enumerator to prevent the GC from destroying it before the enumerator is destroyed. --- gstreamer-sharp/Iterator.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gstreamer-sharp/Iterator.cs b/gstreamer-sharp/Iterator.cs index 5eb12bd947..d9b690b58d 100644 --- a/gstreamer-sharp/Iterator.cs +++ b/gstreamer-sharp/Iterator.cs @@ -7,6 +7,7 @@ namespace Gst { internal class Enumerable : IEnumerable { private class Enumerator : IEnumerator { + Enumerable enumerable; Hashtable seen = new Hashtable (); IntPtr iterator; @@ -57,7 +58,8 @@ namespace Gst { gst_iterator_resync (iterator); } - public Enumerator (IntPtr iterator) { + public Enumerator (Enumerable enumerable, IntPtr iterator) { + this.enumerable = enumerable; this.iterator = iterator; } } @@ -67,11 +69,11 @@ namespace Gst { public Enumerable (IntPtr iterator) { this.iterator = iterator; - this.enumerator = new Enumerator (iterator); + this.enumerator = new Enumerator (this, iterator); } public IEnumerator GetEnumerator () { - return enumerator; + return this.enumerator; } ~Enumerable () { @@ -79,11 +81,11 @@ namespace Gst { gst_iterator_free (iterator); } - [DllImport("libgstreamer-0.10.dll") ] + [DllImport ("libgstreamer-0.10.dll") ] static extern int gst_iterator_next (IntPtr iterator, out IntPtr elem); - [DllImport("libgstreamer-0.10.dll") ] + [DllImport ("libgstreamer-0.10.dll") ] static extern void gst_iterator_resync (IntPtr iterator); - [DllImport("libgstreamer-0.10.dll") ] + [DllImport ("libgstreamer-0.10.dll") ] static extern void gst_iterator_free (IntPtr iterator); }