Skip to content

context: clamp to_window_coords result to window bounds - #7

Merged
igagis merged 2 commits into
cppfw:mainfrom
igagis-bot:fix/offscreen-scissor-clamp
Nov 26, 2026
Merged

igagis merged 2 commits into
cppfw:mainfrom
igagis-bot:fix/offscreen-scissor-clamp

Conversation

@igagis-bot

Copy link
Copy Markdown
Contributor

Problem

In the Vulkan variant, when a clipped widget (e.g. a ruis::window) is dragged so part of it extends past the app window's left or top edge, its contents disappear entirely. The OpenGL variant clips correctly at the window edge.

Root cause

context::to_window_coords() converts NDC -> window pixels with static_cast<uint32_t> and had no clamp (the GL variant clamps via p = max(p, {0,0})).

An off-screen corner has NDC < -1, so (ndc + 1) * 0.5 * size is a negative float. Cast to uint32_t it wraps to ~2^32. The scissor rectangle is then built from min/max of the two corners, so its origin lands on the widget's right edge x with a near-2^32 width - the entire visible portion ends up outside the scissor and nothing is drawn.

Fix

Clamp the computed pixel coords to [0, w] x [0, h] before the uint32_t cast (mirrors the GL clamp, and also clamps the max side so the scissor can never overshoot the render area).

Verified: full build + all tests pass; manual run confirms the window now clips at the app window edge instead of its contents vanishing.

Without the clamp a widget corner outside the window (e.g. when a
ruis::window is dragged past the app window's left or top edge)
produces a negative value which wraps to a huge number when cast to
uint32_t, corrupting the scissor rectangle so the widget's contents
disappear instead of being clipped at the window edge (the GL variant
already clamps).
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (77a58a9) to head (a42ddf1).

Files with missing lines Patch % Lines
src/ruis/render/vulkan/context.cpp 0.00% 5 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main      #7   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         24      24           
  Lines       1389    1388    -1     
  Branches     499     499           
=====================================
+ Misses      1389    1388    -1     

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

Comment thread src/ruis/render/vulkan/context.cpp Resolved
Comment thread src/ruis/render/vulkan/context.cpp Resolved
Comment thread src/ruis/render/vulkan/context.cpp Resolved
Comment thread src/ruis/render/vulkan/context.cpp Resolved
@igagis
igagis merged commit 44c215e into cppfw:main Nov 26, 2026
23 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