diff Applications/Generic/GuiAdapter.cpp @ 947:1091b2adeb5a toa2019081001

Fixed animation frame stopping when returning false + big work on the OpenGL objects to make them lost context-safe + debug code to forcefully tag a context as lost + debug macros
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 10 Aug 2019 13:07:31 +0200
parents 86ac61a040c9
children ac88989817e3
line wrap: on
line diff
--- a/Applications/Generic/GuiAdapter.cpp	Tue Aug 06 15:07:23 2019 +0200
+++ b/Applications/Generic/GuiAdapter.cpp	Sat Aug 10 13:07:31 2019 +0200
@@ -550,10 +550,21 @@
   // SDL ONLY
   void GuiAdapter::OnAnimationFrame()
   {
+    std::vector<size_t> disabledAnimationHandlers;
     for (size_t i = 0; i < animationFrameHandlers_.size(); i++)
     {
       // TODO: fix time 
-      (*(animationFrameHandlers_[i].first))(0, animationFrameHandlers_[i].second);
+      bool goOn = (*(animationFrameHandlers_[i].first))(0, animationFrameHandlers_[i].second);
+
+      // If the function returns false, we need to emulate what happens in Web 
+      // and remove the function from the handlers...
+      if (!goOn)
+        disabledAnimationHandlers.push_back(i);
+    }
+    for (size_t i = 0; i < disabledAnimationHandlers.size(); i++)
+    {
+      ORTHANC_ASSERT(animationFrameHandlers_.begin() + disabledAnimationHandlers[i] < animationFrameHandlers_.end());
+      animationFrameHandlers_.erase(animationFrameHandlers_.begin() + disabledAnimationHandlers[i]);
     }
   }
 
@@ -695,6 +706,10 @@
     }
   }
 
+
+  // extern void Debug_SetContextToBeKilled(std::string title);
+  // extern void Debug_SetContextToBeRestored(std::string title);
+
   // SDL ONLY
   void GuiAdapter::RequestAnimationFrame(OnAnimationFrameFunc func, void* userData)
   {
@@ -846,6 +861,23 @@
             // window.GetWindow().ToggleMaximize(); //TODO: move to particular handler
             break;
 
+          // This commented out code was used to debug the context
+          // loss/restoring code (2019-08-10)
+          // case SDLK_k:
+          //   {
+          //     SDL_Window* window = SDL_GetWindowFromID(event.window.windowID);
+          //     std::string windowTitle(SDL_GetWindowTitle(window));
+          //     Debug_SetContextToBeKilled(windowTitle);
+          //   }
+          //   break;
+          // case SDLK_l:
+          //   {
+          //     SDL_Window* window = SDL_GetWindowFromID(event.window.windowID);
+          //     std::string windowTitle(SDL_GetWindowTitle(window));
+          //     Debug_SetContextToBeRestored(windowTitle);
+          //   }
+          //   break;
+
           case SDLK_q:
             stop = true;
             break;