# C++ glGenBuffers does not return proper VBOID when called in thread [closed]

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);
glfwMakeContextCurrent(mainWindow);
}

void terrainGeneratorLoop() { //This is in another thread!
glfwMakeContextCurrent(sharedWindow);
while(running){

/* Generate vertex data for terrain */

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);
}
glfwMakeContextCurrent(nullptr);
}


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.

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