Arreglado fallo de segmentación al cerrar el programa

Esto era causado porque main llamaba a "glfwTerminate", lo que desvincula las
funciones de OpenGL y despues de eso el destructor de Renderer intenta usarlas.

Para solucionarlo se registra "glfwTerminate" como una función atexit para
que se llame despues que el destructor de Renderer.
parent 221f238d
Showing with 16 additions and 1 deletions
...@@ -73,6 +73,15 @@ int main() { ...@@ -73,6 +73,15 @@ int main() {
panic("Failed to initialize GLFW"); panic("Failed to initialize GLFW");
} }
// Tenemos que registrar glfwTerminate antes de acceder a Renderer
// para que su destructor se ejecute antes que glfwTerminate
// (se destruyen en orden inverso de creación)
int couldCallAtExit = (std::atexit(glfwTerminate) == 0);
if (!couldCallAtExit) {
PAG::log << "AVISO: No se pudo registrar glfwTerminate atexit" << std::endl;
PAG::log << "AVISO: puede que esto cause un SEGFAULT cuando finalize el programa" << std::endl;
}
glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
...@@ -135,5 +144,11 @@ int main() { ...@@ -135,5 +144,11 @@ int main() {
PAG::GUI::getInstance().shutdown(); PAG::GUI::getInstance().shutdown();
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate();
// Si no pudimos registrar atexit lo tenemos que hacer nosotros
// Esto causará un SEGFAULT cuando el destructor de Renderer intente llamar
// a cualquier función de OpenGL porque glfwTerminate las desvincula
if (!couldCallAtExit) {
glfwTerminate();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment