diff options
author | Benjamin Otte <otte@redhat.com> | 2015-01-18 22:24:35 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-01-19 01:12:50 +0100 |
commit | 0fef59b48643f0de4cb919ba582bbcf97d3891f1 (patch) | |
tree | d9dfaeb875ee37fe1aed5bbb4bca6c061882b6aa | |
parent | e649c8773f0357df19f4e28aabf40a203a39c409 (diff) | |
download | gtk+-0fef59b48643f0de4cb919ba582bbcf97d3891f1.tar.gz |
stylecontext: Be more graceful when save() isn't matched with restore()
Instead of asserting, just print a g_warning() and try to work around
the problem.
I hope that g_warning() isn't too spammy for people that are hit with
it.
Also clarify the docs that not restore()ing after a save() is a bad
idea.
https://bugzilla.gnome.org/show_bug.cgi?id=743101
-rw-r--r-- | gtk/gtkstylecontext.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 5b9a5ee8ed..21a2b5bda4 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -1593,11 +1593,13 @@ gtk_style_context_get_parent (GtkStyleContext *context) * gtk_style_context_save: * @context: a #GtkStyleContext * - * Saves the @context state, so all modifications done through + * Saves the @context state, so temporary modifications done through * gtk_style_context_add_class(), gtk_style_context_remove_class(), - * gtk_style_context_add_region(), gtk_style_context_remove_region() - * or gtk_style_context_set_junction_sides() can be reverted in one - * go through gtk_style_context_restore(). + * gtk_style_context_set_state(), etc. can quickly be reverted + * in one go through gtk_style_context_restore(). + * + * The matching call to gtk_style_context_restore() must be done + * before GTK returns to the main loop. * * Since: 3.0 **/ @@ -2926,12 +2928,19 @@ _gtk_style_context_validate (GtkStyleContext *context, if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes)) return; - g_assert (!gtk_style_context_is_saved (context)); + if (G_UNLIKELY (gtk_style_context_is_saved (context))) + { + g_warning ("unmatched gtk_style_context_save/restore() detected while validating context for %s %p", + priv->widget ? gtk_widget_get_name (priv->widget) : "widget path", + priv->widget ? (gpointer) priv->widget : (gpointer) priv->widget_path); + cssnode = gtk_style_context_get_root (context); + } + else + cssnode = priv->cssnode; priv->pending_changes = 0; gtk_style_context_set_invalid (context, FALSE); - cssnode = priv->cssnode; current = g_object_ref (cssnode->values); /* Try to avoid invalidating if we can */ @@ -2946,13 +2955,13 @@ _gtk_style_context_validate (GtkStyleContext *context, GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), priv->scale, gtk_style_context_should_create_transitions (context, current) ? current : NULL); + + gtk_style_context_clear_cache (context); gtk_css_node_set_values (cssnode, style); g_object_unref (static_style); g_object_unref (style); - - gtk_style_context_clear_cache (context); } else { |