Skip to content

fix(window): a resize exceeding max_texture_dimension_2d keeps the previous drawable and viewport, and initial surfaces clamp to the limit - #1449

Merged
Hona merged 1 commit into
devfrom
fix/306-wrapped-resize-height
Nov 23, 2026
Merged

Hona merged 1 commit into
devfrom
fix/306-wrapped-resize-height

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

Fixes #306

Root cause

  • Windows can transiently report a negative client height wrapped to u16 in WM_SIZE (for example 65527 for -9) or to u32 from GetClientRect (window.inner_size()).
  • Although Surface::configure is wrapped in error scopes (crates/rune/src/window/surface/configure.rs), Win::resize_surface (crates/rune/src/window/surface/win.rs) and the resize/scale handlers (crates/rune/src/window/host/events.rs) still accepted sizes exceeding max_texture_dimension_2d: overwriting Win::config, marking surface_ok = false (forcing surface teardown and Host::reattach), resizing AlphaSurface to the bogus extent, setting the runtime viewport to 65527 px, and attempting a ~303 MB DIB allocation during Windows CPU boot (crates/rune/src/window/win32/cpu_frame.rs).
  • Initial surface creation and reattach (crates/rune/src/window/surface.rs, crates/rune/src/window/host/create.rs, crates/rune/src/window/win32/handover.rs) passed raw inner_size() without clamping to the texture limit.

Changes

  • Added drawable_size, max_surface_dim, and CPU_MAX_SURFACE_DIM (16_384) in crates/rune/src/window/surface.rs:
    • Existing drawables (Some(prev)): zero or out-of-range sizes (> max_dim) are ignored, keeping the previous valid size (clamped to max_dim on reattach if a new device has a smaller limit).
    • Initial surfaces (None): clamped to 1..=max_dim, including inside surface_config.
  • Updated Win::resize_surface (crates/rune/src/window/surface/win.rs) to validate through drawable_size and max_surface_dim.
  • Updated WindowEvent::Resized, WindowEvent::Moved, and WindowEvent::ScaleFactorChanged (crates/rune/src/window/host/events.rs) plus Host::try_create, Host::reattach (crates/rune/src/window/host/create.rs), Host::open_on_cpu (crates/rune/src/window/win32/cpu_frame.rs), and handover::prepare (crates/rune/src/window/win32/handover.rs) to clamp initial sizes and derive the runtime viewport from the accepted config dimensions.
  • Added regression test window::tests::a_drawable_never_takes_a_size_exceeding_the_texture_limit in crates/rune/src/window/tests.rs and a changelog fragment in changelog/unreleased/2026-11-23-wrapped-resize-height.md.

Verification

  • Confirmed window::tests::a_drawable_never_takes_a_size_exceeding_the_texture_limit failed before the fix and passed after:
    • cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid a_drawable_never_takes_a_size_exceeding_the_texture_limit (1 passed)
    • cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid window:: (108 passed)
    • scripts/file-size.sh (0 errors)
  • Not checked on this machine: live Win32 SetWindowPos GUI reproduction (no desktop window tests run here) and non-Windows target builds (only shared and Windows code changed).

…evious drawable and viewport, and initial surfaces clamp to the limit
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.

Windows: Surface::configure panics when a resize reports a wrapped negative height

1 participant