diff --git a/main.cpp b/main.cpp index 6fc7acd..faaef22 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -8,23 +10,33 @@ int main(int, char**) { if (!glfwInit()) return 1; + std::atexit(glfwTerminate); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - GLFWwindow* window = glfwCreateWindow(1900, 720, "microsa", nullptr, nullptr); + static GLFWwindow* window = glfwCreateWindow(1900, 720, "microsa", nullptr, nullptr); if (window == nullptr) { - glfwTerminate(); return 1; } + static auto DestroyWindow = []() { + glfwDestroyWindow(window); + }; + std::atexit(DestroyWindow); glfwMakeContextCurrent(window); glfwSwapInterval(1); IMGUI_CHECKVERSION(); ImGui::CreateContext(); + static auto ImGuiDestroyContext = []() { + ImGui::DestroyContext(); + }; + std::atexit(ImGuiDestroyContext); ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; ImGui::StyleColorsDark(); ImGui_ImplGlfw_InitForOpenGL(window, true); + std::atexit(ImGui_ImplGlfw_Shutdown); ImGui_ImplOpenGL3_Init("#version 130"); + std::atexit(ImGui_ImplOpenGL3_Shutdown); int waterfall_width = 1600; int waterfall_height = 700; @@ -86,12 +98,5 @@ int main(int, char**) glfwSwapBuffers(window); } - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); - - glfwDestroyWindow(window); - glfwTerminate(); - return 0; }