{"action":"opened","issue":{"url":"https://api.github.com/repos/stevenlovegrove/Pangolin/issues/393","repository_url":"https://api.github.com/repos/stevenlovegrove/Pangolin","labels_url":"https://api.github.com/repos/stevenlovegrove/Pangolin/issues/393/labels{/name}","comments_url":"https://api.github.com/repos/stevenlovegrove/Pangolin/issues/393/comments","events_url":"https://api.github.com/repos/stevenlovegrove/Pangolin/issues/393/events","html_url":"https://github.com/stevenlovegrove/Pangolin/issues/393","id":345759273,"node_id":"MDU6SXNzdWUzNDU3NTkyNzM=","number":393,"title":"Using shared context in mutliple threads","user":{"login":"christian-rauch","id":8226248,"node_id":"MDQ6VXNlcjgyMjYyNDg=","avatar_url":"https://avatars0.githubusercontent.com/u/8226248?v=4","gravatar_id":"","url":"https://api.github.com/users/christian-rauch","html_url":"https://github.com/christian-rauch","followers_url":"https://api.github.com/users/christian-rauch/followers","following_url":"https://api.github.com/users/christian-rauch/following{/other_user}","gists_url":"https://api.github.com/users/christian-rauch/gists{/gist_id}","starred_url":"https://api.github.com/users/christian-rauch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christian-rauch/subscriptions","organizations_url":"https://api.github.com/users/christian-rauch/orgs","repos_url":"https://api.github.com/users/christian-rauch/repos","events_url":"https://api.github.com/users/christian-rauch/events{/privacy}","received_events_url":"https://api.github.com/users/christian-rauch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-30T13:32:07Z","updated_at":"2018-07-30T13:32:07Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I am trying to use Pangolin (X11+GLX) from multiple threads, i.e. I am creating a window in the main thread and drawing into this window from another thread.\r\n\r\nHere is the modified HelloPangolin example, using a thread to draw into the window:\r\n\r\n```\r\n#include <pangolin/pangolin.h>\r\n#include <thread>\r\n#include <pangolin/display/display_internal.h>\r\n\r\nvoid setup() {\r\n    pangolin::CreateWindowAndBind(\"Main\",640,480);\r\n    glEnable(GL_DEPTH_TEST);\r\n\r\n    std::cout << \"current ctx setup: \" << pangolin::GetCurrentContext() << std::endl;\r\n}\r\n\r\nvoid run() {\r\n    std::cout << \"current ctx run: \" << pangolin::GetCurrentContext() << std::endl;\r\n\r\n//    pangolin::BindToContext(\"Main\");    // <- this blocks\r\n    pangolin::FindContext(\"Main\")->MakeCurrent();\r\n\r\n    std::cout << \"current ctx run: \" << pangolin::GetCurrentContext() << std::endl;\r\n\r\n    // Define Projection and initial ModelView matrix\r\n    pangolin::OpenGlRenderState s_cam(\r\n        pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),\r\n        pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)\r\n    );\r\n\r\n    // Create Interactive View in window\r\n    pangolin::Handler3D handler(s_cam);\r\n    pangolin::View& d_cam = pangolin::CreateDisplay()\r\n            .SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)\r\n            .SetHandler(&handler);\r\n\r\n    while( !pangolin::ShouldQuit() )\r\n    {\r\n        // Clear screen and activate view to render into\r\n        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r\n        d_cam.Activate(s_cam);\r\n\r\n        // Render OpenGL Cube\r\n        pangolin::glDrawColouredCube();\r\n\r\n        // Swap frames and Process Events\r\n        pangolin::FinishFrame();\r\n    }\r\n}\r\n\r\nint main( int /*argc*/, char** /*argv*/ )\r\n{\r\n    setup();\r\n\r\n    std::thread render_loop;\r\n    render_loop = std::thread(run);\r\n    render_loop.join();\r\n\r\n    return 0;\r\n}\r\n```\r\nGetting the context via `pangolin::BindToContext(\"Main\")` blocks the execution of `run()`. `pangolin::FindContext(\"Main\")->MakeCurrent()` returns the same context, but the window is empty (black). Calling `run()` outside of a thread correctly draws the cube.\r\n\r\nWhat is the right way to use Pangolin in multiple threads?\r\n"}}
{"actor":{"display_login":"christian-rauch"}}