From 79e2ffff2a7ca65f0346822e1d2fbcfb9d2cb36a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 28 Aug 2024 04:10:41 +0200 Subject: [PATCH] LXVST: fix crash at exit if Linux VSTs are disabled or X11 connection fails --- gtk2_ardour/linux_vst_gui_support.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/linux_vst_gui_support.cc b/gtk2_ardour/linux_vst_gui_support.cc index 80bc465b0f..c321071c57 100644 --- a/gtk2_ardour/linux_vst_gui_support.cc +++ b/gtk2_ardour/linux_vst_gui_support.cc @@ -58,7 +58,7 @@ static VSTState * vstfx_first = NULL; const char magic[] = "VSTFX Plugin State v002"; -static volatile int gui_quit = 0; +static volatile int gui_state = -1; /*This will be our connection to X*/ @@ -330,7 +330,7 @@ gui_event_loop (void* ptr) clock1 = g_get_monotonic_time(); /*The 'Forever' loop - runs the plugin UIs etc - based on the FST gui event loop*/ - while (!gui_quit) + while (gui_state == 0) { /* handle window creation requests, destroy requests, and run idle callbacks */ @@ -464,7 +464,7 @@ again: clock1 = g_get_monotonic_time(); } - if (!gui_quit && may_sleep && elapsed_time_ms + 1 < LXVST_sched_timer_interval) { + if (0 == gui_state && may_sleep && elapsed_time_ms + 1 < LXVST_sched_timer_interval) { Glib::usleep (1000 * (LXVST_sched_timer_interval - elapsed_time_ms - 1)); } } @@ -506,7 +506,7 @@ normally started in globals.cc*/ int vstfx_init (void* ptr) { - assert (gui_quit == 0); + assert (gui_state == -1); pthread_mutex_init (&plugin_mutex, NULL); int thread_create_result; @@ -542,6 +542,7 @@ int vstfx_init (void* ptr) } /*We have a connection to X - so start the gui event loop*/ + gui_state = 0; /*Create the thread - use default attrs for now, don't think we need anything special*/ @@ -555,7 +556,7 @@ int vstfx_init (void* ptr) XCloseDisplay (LXVST_XDisplay); LXVST_XDisplay = 0; - gui_quit = 1; + gui_state = 1; return -1; } @@ -567,10 +568,10 @@ int vstfx_init (void* ptr) void vstfx_exit () { - if (gui_quit) { + if (gui_state) { return; } - gui_quit = 1; + gui_state = 1; /*We need to pthread_join the gui_thread here so we know when it has stopped*/