Search code examples
openglopengl-3

Segmentation fault when calling glDrawElementsInstanced


I found that changing glDrawElements to glDrawElementInstanced results in segfault in otherwise valid program. No problem compiling. gdb says that glDrawElementInstanced is what segfaults. Can anyone guess a problem?

Running on x86_64 GNU/Linux.

Part of CMakeLists.txt:

cmake_minimum_required (VERSION 2.6)
project (sph)

find_package(OpenGL REQUIRED)

include_directories(
    /usr/nvidia-current
.
)

set(ALL_LIBS
    ${OPENGL_LIBRARY}
    glfw
    GLEW
)

add_definitions(
    -D_CRT_SECURE_NO_WARNINGS
)

target_link_libraries(sph
    ${ALL_LIBS}
)

Site of segfault:

glDrawElementsInstanced(
            GL_TRIANGLES,
            indices.size(),
            GL_UNSIGNED_SHORT,
            (void *)0,
            2
        );

Solution

    1. Did you make sure that you have at least a OpenGL 3.1 context available?
    2. Did you check if the glDrawElementInstanced is not NULL after loading it via GLEW?