Skip to content

render: make factory's shared rendering context current when the last render context is destroyed - #199

Merged
igagis merged 4 commits into
cppfw:mainfrom
igagis-bot:fix-teardown-current-context
Nov 26, 2026
Merged

igagis merged 4 commits into
cppfw:mainfrom
igagis-bot:fix-teardown-current-context

Conversation

@igagis-bot

Copy link
Copy Markdown
Contributor

When the last ruis::render::context is destroyed, no rendering context remains current on the thread. On Windows (WGL), any subsequent GL call then fails with GL_INVALID_OPERATION — including the destruction of the shared render objects (shaders, buffers, ...) owned by the ruis::render::factory, which happens right after the contexts are destroyed on application shutdown.

Add a protected virtual ruis::render::factory::bind() (empty by default, for renderers without a notion of a current context, e.g. Vulkan) and call it from ~context() when no render contexts are left, so that the factory's shared rendering context is made current before the shared render objects are destroyed. GL-based renderer factories override bind() to make their shared (headless) GL context current (companion PRs: cppfw/ruis-render-opengl and cppfw/ruis-render-opengles).

native_window::bind_rendering_context() is made public so the factories can call it directly; this removes the need for the friend class ruis::render::factory relation and the former protected factory::bind(native_window&) helper.

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 28.55%. Comparing base (f001323) to head (d2c4fb6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
+ Coverage   28.53%   28.55%   +0.01%     
==========================================
  Files         239      239              
  Lines        8943     8945       +2     
  Branches     2785     2785              
==========================================
+ Hits         2552     2554       +2     
  Misses       6057     6057              
  Partials      334      334              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread src/ruis/render/native_window.hpp Resolved
Comment thread src/ruis/render/native_window.hpp Resolved
igagis
igagis previously approved these changes Nov 26, 2026
igagis
igagis previously approved these changes Nov 26, 2026
@igagis
igagis merged commit b765979 into cppfw:main Nov 26, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants