Browse Source

bug: handle glfw gracious shutdown

Douglas Andreani 1 year ago
parent
commit
4ab971238d
2 changed files with 13 additions and 8 deletions
  1. 6 1
      src/App.cpp
  2. 7 7
      src/BaseWindow.cpp

+ 6 - 1
src/App.cpp

@@ -1,6 +1,9 @@
 #include "App.h"
 #include "Audio.h"
+#include "BaseWindow.h"
+
 #include <memory>
+#include <iostream>
 
 App::App()
 {
@@ -11,5 +14,7 @@ App::App()
 
 void App::Run()
 {
-    m_window->run();
+    if (m_window->run()) {
+        std::cout << "Something wrong happened. Quitting.\n";
+    }
 }

+ 7 - 7
src/BaseWindow.cpp

@@ -18,6 +18,10 @@ BaseWindow::BaseWindow(int width, int height, const char *title, Color clear_col
 
 BaseWindow::~BaseWindow()
 {
+    ImGui_ImplOpenGL3_Shutdown();
+    ImGui_ImplGlfw_Shutdown();
+    ImGui::DestroyContext();
+    glfwDestroyWindow(m_window);
     glfwTerminate();
 }
 
@@ -36,7 +40,7 @@ int BaseWindow::run()
         std::cout << "could not intialize GLFW Window"
                   << "\n";
         glfwTerminate();
-        return -1;
+        return 1;
     }
 
     glfwMakeContextCurrent(m_window);
@@ -44,7 +48,7 @@ int BaseWindow::run()
     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
     {
         std::cout << "Failed to initialize GLAD" << std::endl;
-        return -1;
+        return 1;
     }
 
     glfwSetFramebufferSizeCallback(m_window, window_resize_callback);
@@ -139,10 +143,6 @@ int BaseWindow::run()
     }
 
     // Unload and destroy
-    ImGui_ImplOpenGL3_Shutdown();
-    ImGui_ImplGlfw_Shutdown();
-    ImGui::DestroyContext();
-    glfwDestroyWindow(m_window);
-    glfwTerminate();
+    
     return 0;
 }