use atexit

This commit is contained in:
Sebastien Bourdeauducq 2023-08-23 15:06:05 +08:00
parent fb2bafb215
commit 26af4416c2

View File

@ -1,3 +1,5 @@
#include <cstdlib>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <imgui.h> #include <imgui.h>
@ -8,23 +10,33 @@ int main(int, char**)
{ {
if (!glfwInit()) if (!glfwInit())
return 1; return 1;
std::atexit(glfwTerminate);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 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) { if (window == nullptr) {
glfwTerminate();
return 1; return 1;
} }
static auto DestroyWindow = []() {
glfwDestroyWindow(window);
};
std::atexit(DestroyWindow);
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glfwSwapInterval(1); glfwSwapInterval(1);
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
static auto ImGuiDestroyContext = []() {
ImGui::DestroyContext();
};
std::atexit(ImGuiDestroyContext);
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplGlfw_InitForOpenGL(window, true);
std::atexit(ImGui_ImplGlfw_Shutdown);
ImGui_ImplOpenGL3_Init("#version 130"); ImGui_ImplOpenGL3_Init("#version 130");
std::atexit(ImGui_ImplOpenGL3_Shutdown);
int waterfall_width = 1600; int waterfall_width = 1600;
int waterfall_height = 700; int waterfall_height = 700;
@ -86,12 +98,5 @@ int main(int, char**)
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0; return 0;
} }