diff Applications/IBasicApplication.cpp @ 61:ca644004d2ee wasm

MAJOR - removal of Start/Stop and observers in IWidget
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 May 2017 17:55:13 +0200
parents d20e25cfcf3a
children 298f375dcb68
line wrap: on
line diff
--- a/Applications/IBasicApplication.cpp	Wed May 10 16:10:47 2017 +0200
+++ b/Applications/IBasicApplication.cpp	Wed May 10 17:55:13 2017 +0200
@@ -226,8 +226,6 @@
         title = "Stone of Orthanc";
       }
 
-      context.Start();
-
       {
         /**************************************************************
          * Run the application inside a SDL window
@@ -238,9 +236,23 @@
         SdlWindow window(title.c_str(), width, height, opengl);
         SdlEngine sdl(window, context);
 
+        {
+          BasicApplicationContext::ViewportLocker locker(context);
+          locker.GetViewport().Register(sdl);  // (*)
+        }
+
+        context.Start();
         sdl.Run();
 
         LOG(WARNING) << "Stopping the application";
+
+        // Don't move the "Stop()" command below out of the block,
+        // otherwise the application might crash, because the
+        // "SdlEngine" is an observer of the viewport (*) and the
+        // update thread started by "context.Start()" would call a
+        // destructed object (the "SdlEngine" is deleted with the
+        // lexical scope).
+        context.Stop();
       }
 
 
@@ -248,15 +260,7 @@
        * Finalize the application
        ****************************************************************/
 
-      context.Stop();
-
       LOG(WARNING) << "The application has stopped";
-
-      {
-        BasicApplicationContext::ViewportLocker locker(context);
-        locker.GetViewport().ResetStatusBar();
-      }
-      
       application.Finalize();
     }
     catch (Orthanc::OrthancException& e)