2 votes

Le projet C++ plante après glewinit()

(J'utilise Clion et Cmake sur Macosx Intel chip)

Je souhaite créer une application Windows avec GLEW. Mais j'obtiens cette erreur :

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

J'ai entendu dire qu'il fallait définir "GLEW_STATIC" dans le prétraitement. Mais je n'ai aucune idée de la façon dont Clion fonctionne

Mon main.cpp :

#include "GL/glew.h"
#include <GLFW/glfw3.h>

int main()
{
    GLFWwindow* window;
    if (!glfwInit())
        return -1;
    glewInit();
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    while (!glfwWindowShouldClose(window))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

et mon cmake :

cmake_minimum_required(VERSION 3.22)
project(renderer)

set(CMAKE_CXX_STANDARD 14)
include_directories(/usr/local/Cellar/glfw/3.3.8/include)
include_directories(/usr/local/Cellar/glew/2.2.0_1/include)

add_definitions(-DGLEW_STATIC)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreFoundation -framework OpenGL -framework GLUT ")
add_executable(renderer main.cpp)
target_link_libraries(renderer /usr/local/Cellar/glfw/3.3.8/lib/libglfw.3.3.dylib)
target_link_libraries(renderer /usr/local/Cellar/glew/2.2.0_1/lib/libGLEW.2.2.dylib)

Comment résoudre ce problème ?

3voto

genpfault Points 28836

glewInit() nécessite une contexte OpenGL actuel pour fonctionner correctement. Comme écrit dans votre code glewInit() échouera et laissera son glClear() le pointeur de fonction est fixé à nullptr .

Appeler glewInit() après glfwMakeContextCurrent() Retour". GLFW_NO_ERROR y vérifier qu'il renvoie GLEW_OK .

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X