Implement cross-platform GL context helpers for overlay#100
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| void Overlay::shutdown() { | ||
| #ifndef LIZARD_TEST | ||
| stop(); | ||
| // Release GL resources after the render loop has stopped | ||
| #ifdef _WIN32 | ||
| if (m_window.device && m_window.glContext) { | ||
| wglMakeCurrent((HDC)m_window.device, (HGLRC)m_window.glContext); | ||
| } | ||
| #elif defined(__linux__) | ||
| if (m_window.native && m_window.glContext) { | ||
| Display *dpy = glXGetCurrentDisplay(); | ||
| if (dpy) { | ||
| glXMakeCurrent(dpy, (GLXDrawable)m_window.native, (GLXContext)m_window.glContext); | ||
| } | ||
| } | ||
| #elif defined(__APPLE__) | ||
| if (m_window.glContext) { | ||
| auto makeCurrent = reinterpret_cast<void (*)(id, SEL)>(objc_msgSend); | ||
| makeCurrent((id)m_window.glContext, sel_getUid("makeCurrentContext")); | ||
| } | ||
| #endif | ||
| platform::make_context_current(m_window); | ||
| m_texture.reset(); | ||
| m_vbo.reset(); | ||
| m_instance.reset(); | ||
| m_vao.reset(); | ||
| m_program.reset(); | ||
| platform::clear_current_context(m_window); | ||
| platform::destroy_window(m_window); |
There was a problem hiding this comment.
Coordinate GL context teardown with render thread
The new helper in shutdown() calls platform::make_context_current(m_window) and immediately deletes GL objects even though the render loop runs on a separate thread. In main() the exit path requests the render thread to stop and then invokes overlay.shutdown() without waiting for the thread to finish, so the context is still current on the render thread when shutdown re‑binds it or destroys it. This can leave the running thread executing render()/swap_buffers() with no current context or with a destroyed device, which on GLX/WGL typically produces GLXBadDrawable/wglDeleteContext failures or outright crashes. The shutdown path needs to join the render thread (or otherwise wait for run() to clear the context) before stealing or deleting the GL context.
Useful? React with 👍 / 👎.
|
@codex fix comments |
|
Summary
Testing
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_69069caf380883258e184f40f7077727