st/theme-node: Forget properties cache on stylesheet change

To avoid `node->properties` pointing to freed memory after each
`st_theme_unload_stylesheet`, flush the cache that is `node->properties`.
They will be reloaded as soon as they are required by `ensure_properties`.

And yes `node->stylesheets_changed_id` already existed, but was unused.

Why not just fix Croco? Croco does not use proper reference counting
everywhere it should, and retrofitting it would be difficult due to the
recursive nature of `CRDeclaration`.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7339
... but mostly reported in
https://github.com/micheleg/dash-to-dock/issues/2179 and its duplicates.
This commit is contained in:
Daniel van Vugt 2024-03-28 14:58:54 +08:00
parent 6c3b6f6b24
commit cc5a41d0ff
2 changed files with 15 additions and 1 deletions

View file

@ -105,7 +105,7 @@ struct _StThemeNode {
int box_shadow_min_width;
int box_shadow_min_height;
guint stylesheets_changed_id;
gulong stylesheets_changed_id;
CoglTexture *border_slices_texture;
CoglPipeline *border_slices_pipeline;

View file

@ -75,6 +75,10 @@ maybe_free_properties (StThemeNode *node)
cr_declaration_destroy (node->inline_properties);
node->inline_properties = NULL;
}
g_clear_signal_handler (&node->stylesheets_changed_id, node->theme);
node->properties_computed = FALSE;
}
static void
@ -472,6 +476,16 @@ ensure_properties (StThemeNode *node)
node->n_properties = properties->len;
node->properties = (CRDeclaration **)g_ptr_array_free (properties, FALSE);
}
if (!node->stylesheets_changed_id)
{
node->stylesheets_changed_id =
g_signal_connect_object (node->theme,
"custom-stylesheets-changed",
G_CALLBACK (maybe_free_properties),
G_OBJECT (node),
G_CONNECT_SWAPPED);
}
}
}