Following the advice of this thread, I am trying to initialize GLFW and handle all rendering in a separate thread while computation is performed on the main thread. Several threads I’ve found say that functions like glfwCreateWindow can be called from any thread as long as that thread also called glfwInit (source). Yet when I call glfwCreateWindow() on this second thread, I get a variety of colorful error messages including “[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread”. A minimal example looks like this:
void myfunc() {
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
getchar();
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
GLFWwindow * window = glfwCreateWindow(1024, 768, "My Window", NULL, NULL);
return;
}
int main() {
std::thread foo(myfunc);
foo.join();
return 0;
}
Do you know why this is? Is there any way I can do all OpenGL/GLFW handling in this foo thread instead of the main one?
For reference, I am running Mac OS Sierra 10.12.6 with GLFW 3.2.1 on a 2015 Macbook Pro.
As per @mmozeiko’s answer the stackoverflow answer about calling init and create from any thread so long as it was the same was incorrect, indeed the question refers to an older API and FAQ. I’ve posted a reply to help clarify (I hope it does, let me know if it’s not sufficiently comprehensible).