Skip to content

Implement cross-platform GL context helpers for overlay#100

Merged
supermarsx merged 2 commits intomainfrom
smx/implement-window-context-management-helpers-2025-11-02
Nov 2, 2025
Merged

Implement cross-platform GL context helpers for overlay#100
supermarsx merged 2 commits intomainfrom
smx/implement-window-context-management-helpers-2025-11-02

Conversation

@supermarsx
Copy link
Owner

Summary

  • add helper declarations to the platform window interface for binding, releasing, and swapping OpenGL contexts
  • implement the helpers on Windows, macOS, and Linux backends using the native APIs
  • update the overlay lifecycle to own the context during the render loop, perform buffer swaps, and clean up with the helpers

Testing

  • not run (not supported in container)

https://chatgpt.com/codex/tasks/task_e_69069caf380883258e184f40f7077727

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 714 to 724
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@supermarsx
Copy link
Owner Author

@codex fix comments

@chatgpt-codex-connector
Copy link

Summary

  • Ensured the shutdown flow in main joins the overlay render thread before tearing down OpenGL resources, avoiding context races during teardown. src/app/main.cppL311-L317

Testing

  • ⚠️ Not run (not requested)

View task →

@supermarsx
Copy link
Owner Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Breezy!

ℹ️ 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".

@supermarsx supermarsx merged commit e79d7ac into main Nov 2, 2025
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant