From 41de6cb6f8ee73a712e305f8c1b6d34090a24523 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 25 Nov 2023 12:02:58 +0000 Subject: Ensure the current scaffold remains valid When a scaffold was being destroyed the currently selected scaffold could become a reference to a destroyed object. This would result in crashes subsequently when the current scaffold was referenced. The change is simply to ensure the selected scaffold is changed to something valid during destruction. --- frontends/gtk/scaffolding.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c index 71c96a8ba..f9d4f6d67 100644 --- a/frontends/gtk/scaffolding.c +++ b/frontends/gtk/scaffolding.c @@ -193,6 +193,18 @@ static void scaffolding_window_destroy(GtkWidget *widget, gpointer data) nsgtk_local_history_hide(); + /* ensure scaffolding being destroyed is not current */ + if (scaf_current == gs) { + scaf_current = NULL; + /* attempt to select nearest scaffold instead of just selecting the first */ + if (gs->prev != NULL) { + scaf_current = gs->prev; + } else if (gs->next != NULL) { + scaf_current = gs->next; + } + } + + /* remove scaffolding from list */ if (gs->prev != NULL) { gs->prev->next = gs->next; } else { -- cgit v1.2.3