From cb31b145c38cfd95d19de132a47e6ff31f0a0a09 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 19 Jan 2017 23:52:30 +0100 Subject: [PATCH] GuiStart: further streamlined the invocation code due to investigating that Heisenbug, I understand the storage layout more clearly. It occured to me that there is no reason to copy the terminationHandler (functor) into an instance variable, since it is easily possible to keep all of the invocation and error handling confined within the scope of the run function, i.e. on stack. So the effective memory layout does not change, but the legibility of the code is improved, since we're able to remove the dtor and simplyfy the ctor and avoid most of the member fields. --- src/common/guifacade.cpp | 2 -- src/gui/guistart.cpp | 39 +++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/common/guifacade.cpp b/src/common/guifacade.cpp index 91b8d0d86..c5087a291 100644 --- a/src/common/guifacade.cpp +++ b/src/common/guifacade.cpp @@ -63,8 +63,6 @@ namespace gui { throw lumiera::error::Fatal("failed to bring up GUI",lumiera_error()); } - ~GuiRunner () { } - bool launchUI (Subsys::SigTerm& terminationHandle) override { diff --git a/src/gui/guistart.cpp b/src/gui/guistart.cpp index c8265b02c..4fbb1bcac 100644 --- a/src/gui/guistart.cpp +++ b/src/gui/guistart.cpp @@ -89,24 +89,17 @@ namespace gui { */ struct GuiLifecycle { - string error_; - Subsys::SigTerm reportOnTermination_; DisplayService activateDisplayService_; ///////////////////////////TICKET #82 will go away once we have a real OutputSlot offered by the UI - GuiLifecycle (Subsys::SigTerm terminationHandler) - : reportOnTermination_(terminationHandler) - , activateDisplayService_() // opens the gui::Display facade interface + GuiLifecycle () + : activateDisplayService_() // opens the gui::Display facade interface { } - ~GuiLifecycle () - { - reportOnTermination_(&error_); // inform main thread that the GUI has been shut down. - } - void - run () + run (Subsys::SigTerm reportOnTermination) { + string errorMsgBuff; try { int argc =0; @@ -114,27 +107,29 @@ namespace gui { // execute the GTK Event Loop____________ GtkLumiera::application().main(argc, argv); /////////////TICKET #1048 : do not access GtkLumiera as singleton, rather just place it as local variable on the stack here - - if (!lumiera_error_peek()) - return; // all went well, normal shutdown - } + } // all went well, regular shutdown + catch (lumiera::Error& problem) { - error_ = problem.what(); + errorMsgBuff = problem.what(); lumiera_error(); // clear error flag - return; } - catch (...){ } - error_ = "unexpected error terminated the GUI."; - return; + catch (...) + { + errorMsgBuff = "unexpected error terminated the GUI."; + } + if (lumiera_error_peek()) + errorMsgBuff = string{lumiera_error()}; + + reportOnTermination(&errorMsgBuff); // inform main thread that the GUI has been shut down. } }; void - runGUI (Subsys::SigTerm reportTermination) + runGUI (Subsys::SigTerm& reportOnTermination) { - GuiLifecycle(reportTermination).run(); + GuiLifecycle{}.run (reportOnTermination); } } // (End) impl details