changeset 23979:fb9b024a6041

avoid SIGABRT on exit from the GUI (bug #50210) * main-window.h, main-window.cc (octave_finished_signal): New signal. (handle_octave_finished): New slot. Terminate and wait for main thread here, then call QApplication::exit. (octave_interpreter::execute): Emit octave_finished_signal here instead of calling QApplication::exit. (main_window::main_window): Connext octave_finished_signal to handle_octave_finished slot. (main_window::~main_window): If m_main_thread is not finished, terminate and wait for it before deleting it.
author John W. Eaton <jwe@octave.org>
date Thu, 31 Aug 2017 15:33:45 -0400
parents 665507c3c29d
children eb6602171d59
files libgui/src/main-window.cc libgui/src/main-window.h
diffstat 2 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Thu Aug 31 10:30:01 2017 -0700
+++ b/libgui/src/main-window.cc	Thu Aug 31 15:33:45 2017 -0400
@@ -138,7 +138,7 @@
 
   m_app_context->delete_interpreter ();
 
-  qApp->exit (exit_status);
+  emit octave_finished_signal (exit_status);
 }
 
 void
@@ -214,6 +214,9 @@
   connect (m_interpreter, SIGNAL (octave_ready_signal ()),
            doc_browser_window, SLOT (load_info_file ()));
 
+  connect (m_interpreter, SIGNAL (octave_finished_signal (int)),
+           this, SLOT (handle_octave_finished (int)));
+
   m_interpreter->moveToThread (m_main_thread);
 
   m_main_thread->start ();
@@ -235,7 +238,18 @@
   delete _workspace_model;
   delete variable_editor_window;
   delete m_interpreter;
+
+  // We are supposed to arrive here after the main thread is done, but
+  // if that doesn't happen for some reason, then terminate and wait
+  // before deleting it.
+  if (! m_main_thread->isFinished ())
+    {
+      m_main_thread->terminate ();
+      // FIXME: should there be a limit on how long we wait?
+      m_main_thread->wait ();
+    }
   delete m_main_thread;
+
   if (find_files_dlg)
     {
       delete find_files_dlg;
@@ -1892,7 +1906,18 @@
 
   if (_start_gui)
     focus_command_window ();  // make sure that the command window has focus
-
+}
+
+void
+main_window::handle_octave_finished (int exit_status)
+{
+  // The main thread is done, so we can terminate it and wait for it to
+  // finish.
+  m_main_thread->terminate ();
+  // FIXME: should there be a limit on how long we wait?
+  m_main_thread->wait ();
+
+  qApp->exit (exit_status);
 }
 
 void
--- a/libgui/src/main-window.h	Thu Aug 31 10:30:01 2017 -0700
+++ b/libgui/src/main-window.h	Thu Aug 31 15:33:45 2017 -0400
@@ -81,6 +81,7 @@
 signals:
 
   void octave_ready_signal ();
+  void octave_finished_signal (int);
 
 public slots:
 
@@ -246,6 +247,7 @@
   void handle_show_doc (const QString& file);
 
   void handle_octave_ready ();
+  void handle_octave_finished (int);
 
   // find files dialog
   void find_files (const QString& startdir = QDir::currentPath ());