Skip to content

render: restore framebuffer before viewport in frame_buffer::apply() - #204

Merged
igagis merged 1 commit into
cppfw:mainfrom
igagis-bot:fix-viewport-restore-order
Nov 29, 2026
Merged

igagis merged 1 commit into
cppfw:mainfrom
igagis-bot:fix-viewport-restore-order

Conversation

@igagis-bot

Copy link
Copy Markdown
Contributor

Bug

frame_buffer::apply() restored the viewport before the framebuffer:

utki::scope_exit framebuffer_scope_exit(...);  // runs LAST
...
utki::scope_exit viewport_scope_exit(...);    // runs FIRST

Renderers whose set_viewport() computes absolute coordinates from the height of the current render target (OpenGL/OpenGLES' bottom-left-origin glViewport()) therefore restored the screen viewport against the height of the cache framebuffer instead of the window, producing a wrong glViewport() (e.g. negative y) that persisted until the next actual window resize.

This made the rendered image shift (and stay broken) on the next frame after any cached widget was rendered, and only a window resize/restore corrected it.

Fix

Restore the framebuffer first and then the viewport, so the viewport restore always uses the height of the intended target (the screen or the previous framebuffer).

Reproduced with the OpenGL test app: widget tree with cached widgets rendered the whole window shifted down ~80% of screen; minimize/restore corrected it for a single frame, after which the next render re-corrupted the viewport. After this fix, the app renders correctly continuously.

frame_buffer::apply() restored the viewport before the framebuffer.
Renderers whose set_viewport() computes absolute coordinates from the
height of the current render target (e.g. OpenGL's bottom-left origin
glViewport()) therefore restored the screen viewport against the height
of the cache framebuffer instead of the window, producing a wrong
glViewport() that persisted until the next actual resize. This made the
rendered image shift (and stay broken) on the next frame after any
cached widget was rendered, and only a window resize/restore corrected it.

Restore the framebuffer first and then the viewport, so the viewport
restore always uses the height of the intended target.
@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 28.55%. Comparing base (0904c73) to head (86654ec).

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

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

@igagis
igagis merged commit f7304df into cppfw:main Nov 29, 2026
27 checks passed
@igagis-bot
igagis-bot deleted the fix-viewport-restore-order branch November 29, 2026 23:46
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