From fb7672b7fe7492ddecdf4b8d40e3b8958bbf6f2b Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 16:36:08 +0200 Subject: [PATCH 1/4] render: make factory's shared rendering context current when the last render context is destroyed --- src/ruis/render/context.cpp | 5 +++++ src/ruis/render/factory.hpp | 21 +++++++++++++-------- src/ruis/render/native_window.hpp | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ruis/render/context.cpp b/src/ruis/render/context.cpp index d6c926ac5..e6aad5502 100644 --- a/src/ruis/render/context.cpp +++ b/src/ruis/render/context.cpp @@ -61,6 +61,11 @@ context::~context() if (!cur_context_stack.empty()) { cur_context_stack.back()->native_window.get().bind_rendering_context(); + } else { + // no render contexts are left, so make the factory's shared rendering + // context current: the shared render objects created by the factory + // must be destroyed with a valid current context + this->factory.get().bind(); } } diff --git a/src/ruis/render/factory.hpp b/src/ruis/render/factory.hpp index 2dd7d2c38..24a7e87d0 100644 --- a/src/ruis/render/factory.hpp +++ b/src/ruis/render/factory.hpp @@ -45,6 +45,7 @@ along with this program. If not, see . #include "vertex_buffer.hpp" namespace ruis::render { +class context; /** * @brief Render object factory. @@ -62,6 +63,10 @@ namespace ruis::render { */ class factory : public std::enable_shared_from_this { + // ruis::render::context calls the protected bind() when the last render + // context is destroyed, to make the shared rendering context current + friend class context; + public: virtual ~factory() = default; @@ -74,16 +79,16 @@ class factory : public std::enable_shared_from_this } /** - * @brief Make the rendering context of the given native window current. + * @brief Make this factory's shared rendering context current. * - * ruis::render::factory is a friend of ruis::render::native_window and can - * therefore call its private bind_rendering_context(). Concrete renderer - * factories use this to make their headless (shared) GL context current. + * The default (empty) implementation is for renderers that have no notion + * of a current context (e.g. Vulkan). GL-based factories override it to + * make their shared (headless) GL context current. Called by + * ruis::render::context when the last render context is destroyed, so + * that the shared render objects created by the factory can be destroyed + * with a valid current context. */ - void bind(ruis::render::native_window& win) const - { - win.bind_rendering_context(); - } + virtual void bind() const {} public: factory(const factory&) = delete; diff --git a/src/ruis/render/native_window.hpp b/src/ruis/render/native_window.hpp index 8bbe5cdf3..376143ee1 100644 --- a/src/ruis/render/native_window.hpp +++ b/src/ruis/render/native_window.hpp @@ -42,18 +42,19 @@ class factory; class native_window { friend class ruis::render::context; - friend class ruis::render::factory; bool is_vsync_enabled_v = false; bool is_fullscreen_v = false; bool is_maximized_v = false; bool is_minimized_v = false; +public: /** * @brief Bind rendering context to the native window. */ virtual void bind_rendering_context() {} +private: /** * @brief Check if rendering context is bound to the native window. * @return true if rendering context is bound. From 091928932da9c9a134a683721d53040119e4ecc0 Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 17:25:17 +0200 Subject: [PATCH 2/4] render: keep native_window::bind_rendering_context() private (review feedback) --- src/ruis/render/factory.hpp | 12 ++++++++++++ src/ruis/render/native_window.hpp | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ruis/render/factory.hpp b/src/ruis/render/factory.hpp index 24a7e87d0..d0b7d0cd4 100644 --- a/src/ruis/render/factory.hpp +++ b/src/ruis/render/factory.hpp @@ -78,6 +78,18 @@ class factory : public std::enable_shared_from_this return utki::shared_ref(this->shared_from_this()); } + /** + * @brief Make the rendering context of the given native window current. + * + * ruis::render::factory is a friend of ruis::render::native_window and can + * therefore call its private bind_rendering_context(). Concrete renderer + * factories use this to make their headless (shared) GL context current. + */ + void bind(ruis::render::native_window& win) const + { + win.bind_rendering_context(); + } + /** * @brief Make this factory's shared rendering context current. * diff --git a/src/ruis/render/native_window.hpp b/src/ruis/render/native_window.hpp index 376143ee1..8bbe5cdf3 100644 --- a/src/ruis/render/native_window.hpp +++ b/src/ruis/render/native_window.hpp @@ -42,19 +42,18 @@ class factory; class native_window { friend class ruis::render::context; + friend class ruis::render::factory; bool is_vsync_enabled_v = false; bool is_fullscreen_v = false; bool is_maximized_v = false; bool is_minimized_v = false; -public: /** * @brief Bind rendering context to the native window. */ virtual void bind_rendering_context() {} -private: /** * @brief Check if rendering context is bound to the native window. * @return true if rendering context is bound. From 08dc3047bab60e4c65f2422a7aa0358c35b4b7fe Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 17:51:31 +0200 Subject: [PATCH 3/4] render: rename the window binding helper to static bind_window_context(native_window&) --- src/ruis/render/factory.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruis/render/factory.hpp b/src/ruis/render/factory.hpp index d0b7d0cd4..bf850a4dd 100644 --- a/src/ruis/render/factory.hpp +++ b/src/ruis/render/factory.hpp @@ -85,7 +85,7 @@ class factory : public std::enable_shared_from_this * therefore call its private bind_rendering_context(). Concrete renderer * factories use this to make their headless (shared) GL context current. */ - void bind(ruis::render::native_window& win) const + static void bind_window_context(ruis::render::native_window& win) { win.bind_rendering_context(); } From d2c4fb6f375c44bf6607d078054d171d711cb574 Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 18:52:48 +0200 Subject: [PATCH 4/4] ci: pin the renderer harness modules to the fix-factory-bind branch commits --- tests/harness/modules/ruis-render-opengl | 2 +- tests/harness/modules/ruis-render-opengles | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/harness/modules/ruis-render-opengl b/tests/harness/modules/ruis-render-opengl index 7b2a7ecea..332ce39f2 160000 --- a/tests/harness/modules/ruis-render-opengl +++ b/tests/harness/modules/ruis-render-opengl @@ -1 +1 @@ -Subproject commit 7b2a7ecea5c337befdf6fec2d2bf2689a84d381d +Subproject commit 332ce39f29feaa0ea78daa995b2c4d05fd793c6f diff --git a/tests/harness/modules/ruis-render-opengles b/tests/harness/modules/ruis-render-opengles index d742586c1..7f8c040ce 160000 --- a/tests/harness/modules/ruis-render-opengles +++ b/tests/harness/modules/ruis-render-opengles @@ -1 +1 @@ -Subproject commit d742586c1cc6e7dce55adcadb9842a0c3cd0704a +Subproject commit 7f8c040cedeceba45b1865b020d7979f1b744869