app: do not assume that a procedure is still registered after running.

I had the case when "Sphere" script crashed, bringing down the whole script-fu
plug-in (while trying to reproduce #10214). Then after being run, we get a
dangling pointer to a finalized action object.

Even in successful use cases, we will want to give the ability to unregister
normal plug-ins/procedures wrapped as GIMP extensions, and there is also the use
case of temporary procedures, so I'm sure this bug could be reproducible even in
normal non-problematic runs.
This commit is contained in:
Jehan 2023-10-26 22:36:16 +02:00
parent fe8811c119
commit 83a5998547
2 changed files with 13 additions and 1 deletions

View File

@ -362,6 +362,8 @@ gimp_action_history_action_activated (GimpAction *action)
GList *link;
GimpActionHistoryItem *item;
g_return_if_fail (GIMP_IS_ACTION (action));
/* Silently return when called at the wrong time, like when the
* activated action was "quit" and the history is already gone.
*/

View File

@ -157,10 +157,20 @@ gimp_procedure_action_activate (GAction *action,
{
gsize hack = GPOINTER_TO_SIZE (procedure_action->procedure);
g_object_add_weak_pointer (G_OBJECT (action), (gpointer) &action);
gimp_action_emit_activate (GIMP_ACTION (action),
g_variant_new_uint64 (hack));
gimp_action_history_action_activated (GIMP_ACTION (action));
if (action != NULL)
{
g_object_remove_weak_pointer (G_OBJECT (action), (gpointer) &action);
/* An action might disappear between the moment it's run and the
* moment we log it. I experienced this when script-fu crashed, though
* we could imagine that it may be soon possible in normal process too
* for procedures to get un-registered (e.g. in extensions).
*/
gimp_action_history_action_activated (GIMP_ACTION (action));
}
}
}