[gtksourceview] Disconnect notify_buffer when disposing the view.



commit 0dc44d000f619f76bdfe2f43bf44da070a3230c2
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Fri Nov 12 22:53:00 2010 +0100

    Disconnect notify_buffer when disposing the view.
    
    Doing it finalize stage was too late as the buffer at this point may be
    recreated and cause assertion failure in gtk_text_view_finalize ().

 gtksourceview/gtksourceview.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 7b68df0..92c2677 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -156,6 +156,8 @@ struct _GtkSourceViewPrivate
 
 	GtkSourceCompletion	*completion;
 
+	gulong           notify_buffer_id;
+
 	guint            current_line_color_set : 1;
 };
 
@@ -1670,10 +1672,10 @@ gtk_source_view_init (GtkSourceView *view)
 			  G_CALLBACK (view_dnd_drop),
 			  NULL);
 
-	g_signal_connect (view,
-			  "notify::buffer",
-			  G_CALLBACK (notify_buffer),
-			  NULL);
+	view->priv->notify_buffer_id = g_signal_connect (view,
+							 "notify::buffer",
+							 G_CALLBACK (notify_buffer),
+							 NULL);
 }
 
 static GObject *
@@ -1699,6 +1701,15 @@ gtk_source_view_dispose (GObject *object)
 {
 	GtkSourceView *view = GTK_SOURCE_VIEW (object);
 
+	/* notify_buffer() would recreate the buffer if it is set to null,
+	 * and we don't want that to happen when destroying/finalizing */
+	if (view->priv->notify_buffer_id)
+	{
+		g_signal_handler_disconnect (view, view->priv->notify_buffer_id);
+		view->priv->notify_buffer_id = 0;
+	}
+	set_source_buffer (view, NULL);
+
 	if (view->priv->completion != NULL)
 	{
 		g_object_unref (view->priv->completion);
@@ -1739,11 +1750,6 @@ gtk_source_view_finalize (GObject *object)
 	if (view->priv->right_gutter)
 		g_object_unref (view->priv->right_gutter);
 
-	/* notify_buffer() would recreate the buffer if it is set to null,
-	 * and we don't want that to happen when finalizing */
-	g_signal_handlers_disconnect_by_func (view, notify_buffer, NULL);
-	set_source_buffer (view, NULL);
-
 	G_OBJECT_CLASS (gtk_source_view_parent_class)->finalize (object);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]