Skip to content

Commit 516c065

Browse files
stnKrisnaTurboGit
authored andcommitted
Stop Darktable from crashing when closing secondary darkroom window while window is in fullscreen (#18361)
* Consume unfullscreen event when closing secondary window On macOS, when the secondary darkroom window is closed while it is currently full screened, there are events that are still pending that needs to be consumed. When the window is destroyed by gtk_widget_destroy before consuming all of the unfullscreen event, gtk_main() under dt_gui_gtk_run will throw exc_bad_access exception. * Refactor Simplify cleanup so that its all located in _second_window_delete_callback * Let GTK destroy the window Let MacOS handle with the fullscreen state change
1 parent f98dab9 commit 516c065

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/views/darkroom.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void cleanup(dt_view_t *self)
164164
else
165165
dt_conf_set_bool("second_window/last_visible", FALSE);
166166

167-
gtk_widget_destroy(dev->second_wnd);
167+
gtk_window_close(GTK_WINDOW(dev->second_wnd)); // Use close so that _second_window_delete_callback can clean up
168168
dev->second_wnd = NULL;
169169
dev->preview2.widget = NULL;
170170
}
@@ -1392,7 +1392,7 @@ static void _second_window_quickbutton_clicked(GtkWidget *w, dt_develop_t *dev)
13921392
{
13931393
_darkroom_ui_second_window_write_config(dev->second_wnd);
13941394

1395-
gtk_widget_destroy(dev->second_wnd);
1395+
gtk_window_close(GTK_WINDOW(dev->second_wnd)); // Use close so that _second_window_delete_callback can clean up
13961396
dev->second_wnd = NULL;
13971397
dev->preview2.widget = NULL;
13981398
}
@@ -3560,7 +3560,13 @@ static gboolean _second_window_delete_callback(GtkWidget *widget,
35603560
GdkEvent *event,
35613561
dt_develop_t *dev)
35623562
{
3563-
_darkroom_ui_second_window_write_config(dev->second_wnd);
3563+
// We need to be careful when using the second window reference from dev. It could be null at this point
3564+
_darkroom_ui_second_window_write_config(widget);
3565+
3566+
// There's a bug in GTK+3 where fullscreen GTK window on macOS may cause EXC_BAD_ACCESS.
3567+
// We need to unfullscreen the window and consume all pending events first before
3568+
// destroying the window
3569+
gtk_window_unfullscreen(GTK_WINDOW(widget));
35643570

35653571
dev->second_wnd = NULL;
35663572
dev->preview2.widget = NULL;

0 commit comments

Comments
 (0)