I'm currently learning to properly use multithreading in C++ in combination with OpenGL and GLFW, and I encounter a strange bug in my application. I'm generating a procedurally generated terrain in a sidethread, but everytime I want to create the buffer for the generated terrain(chunk), glGenBuffers() just gives me back the value I put in! It does not create a proper buffer. I even checked with gDEBugger, no VBO's created.

Here's the pseudo code:

void init(){ //This is in the main thread!
    sharedWindow = glfwCreateWindow(1, 1, "shared", NULL, NULL);
    mainWindow = glfwCreateWindow(400, 400, "main", NULL, sharedWindow);

void terrainGeneratorLoop() { //This is in another thread!

        /* Generate vertex data for terrain */

        //Upload generated data into GPU:
        unsigned int m_vbo = -1;
        glGenBuffers(1, &m_vbo); //After this call, m_vbo is still -1 (Well actually 4294967295, but you get the point)
        glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
        glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(vertex), &data.at(0), GL_STATIC_DRAW);

I'm pretty sure I'm doing something wrong with my context handling and that shared window. And sorry because of the fact that this is only pseudo code, my structure of the project and classes is way to complex to paste in in here!

EDIT: When I call the terrainGeneratorLoop() in the main thread, everything works as It should.


closed as off-topic by DMGregory Jan 15 '18 at 1:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem must provide a minimal, complete, verifiable example of the issue so that readers can diagnose it without needing to guess, read all of your code, or engage in extensive back-and-forth dialog. For more information, see this meta thread." – DMGregory
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ Have you checked what result glGetError() returns in the case where it fails? \$\endgroup\$ – user1118321 Jun 19 '17 at 1:34

Okay, my code above is correct. I didn't properly store the shared GLFW window! That was somewhere else.


Not the answer you're looking for? Browse other questions tagged or ask your own question.