From 71729da1b8d6657844a4b01078d9345c1cde8b34 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Tue, 24 Nov 2026 01:46:26 +0200 Subject: [PATCH] render: context::current() returns a non-const context& Rendering mutates the active context (frame state, draw commands); renderers must obtain a usable reference without const_cast. The context is owned by the code that created it, so returning a non-const reference is safe. --- src/ruis/render/context.cpp | 2 +- src/ruis/render/context.hpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ruis/render/context.cpp b/src/ruis/render/context.cpp index 77a1857ac..d6c926ac5 100644 --- a/src/ruis/render/context.cpp +++ b/src/ruis/render/context.cpp @@ -23,7 +23,7 @@ along with this program. If not, see . using namespace ruis::render; -std::vector ruis::render::context::cur_context_stack; +std::vector ruis::render::context::cur_context_stack; context::context( utki::shared_ref native_window, // diff --git a/src/ruis/render/context.hpp b/src/ruis/render/context.hpp index 1e686156f..83a11936d 100644 --- a/src/ruis/render/context.hpp +++ b/src/ruis/render/context.hpp @@ -36,7 +36,7 @@ class context : public std::enable_shared_from_this friend class frame_buffer; // Context destruction is rare, so removing from the middle of stack is rare, ok to use std::vector. - static std::vector cur_context_stack; + static std::vector cur_context_stack; protected: utki::shared_ref get_shared_ref() @@ -57,8 +57,10 @@ class context : public std::enable_shared_from_this * @brief Get the currently active rendering context. * * The context stack is maintained by apply(). This returns the top of the stack. + * A non-const reference is returned because rendering mutates the active context + * (frame state, draw commands); the context is owned by the code that created it. */ - static const context& current() noexcept + static context& current() noexcept { utki::assert(!cur_context_stack.empty(), SL); return *cur_context_stack.back();