HLE: keep fitted window dimensions positive #451

Closed
enzoduarte1 wants to merge 1 commit from upstream-pr/451 into main
enzoduarte1 commented 2026-11-24 03:34:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T03:34:10Z.


What

fit_into scales a positive requested window size with as i32. If the work area is very small (for example 1x100 pixels) the scaled size can be below one pixel, truncating to zero even though the title asked for a positive size. A zero width or height is not a usable window.

Positive scaled dimensions are now clamped to at least one pixel. Non-positive inputs, CW_USEDEFAULT, windows that already fit and failed work-area queries keep their existing behavior. The existing fit_into test also covers the tiny-area case and a non-positive size.

This touches a different hunk of lifecycle.rs from PR #419, which changes the WM_SYSCOMMAND handling in window_proc.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-hle --lib lifecycle::: 3 passed.
  • cargo test --workspace --exclude victory-loader -- --test-threads=1: all suites passed.
  • cargo clippy -p victory-hle --all-targets -- -A clippy::field_reassign_with_default -D warnings: clean. The allowed lint is the pre-existing warning fixed by PR #355.
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/lifecycle.rs and git diff --check: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe. Its fixture passes MSVC's /DELAYLOAD flag, which MinGW rejects here; the same failure occurs on unmodified main.

Checklist

  • cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace pass — see the toolchain limitations above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6574013005 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/451). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T03:34:10Z. --- ## What `fit_into` scales a positive requested window size with `as i32`. If the work area is very small (for example 1x100 pixels) the scaled size can be below one pixel, truncating to zero even though the title asked for a positive size. A zero width or height is not a usable window. Positive scaled dimensions are now clamped to at least one pixel. Non-positive inputs, `CW_USEDEFAULT`, windows that already fit and failed work-area queries keep their existing behavior. The existing `fit_into` test also covers the tiny-area case and a non-positive size. This touches a different hunk of `lifecycle.rs` from PR #419, which changes the `WM_SYSCOMMAND` handling in `window_proc`. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-hle --lib lifecycle::`: 3 passed. - `cargo test --workspace --exclude victory-loader -- --test-threads=1`: all suites passed. - `cargo clippy -p victory-hle --all-targets -- -A clippy::field_reassign_with_default -D warnings`: clean. The allowed lint is the pre-existing warning fixed by PR #355. - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/lifecycle.rs` and `git diff --check`: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`. Its fixture passes MSVC's `/DELAYLOAD` flag, which MinGW rejects here; the same failure occurs on unmodified `main`. ## Checklist - [ ] `cargo fmt`, `cargo clippy --workspace --all-targets` and `cargo test --workspace` pass — see the toolchain limitations above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
mercuryVM commented 2026-11-24 06:53:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:08:12Z.

Review: APPROVED


Tested 8ff871b on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed), including load_probe.

  • The early return in fit_into already handles non-positive sizes, an empty work area and sizes that fit, so .max(1) only runs when aw, ah >= 1. The clamped value therefore never goes past the work area, and the centering in the caller stays non-negative.
  • Worked through the new test case: scale = min(1/1000, 100/100) = 0.001, which gives (1, 0.1) and then (1, 1) after the clamp. That matches the assertion.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034014090 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/451#pullrequestreview-6034014090). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T05:08:12Z. **Review:** APPROVED --- Tested 8ff871b on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (264 passed, 0 failed), including `load_probe`. - The early return in `fit_into` already handles non-positive sizes, an empty work area and sizes that fit, so `.max(1)` only runs when `aw, ah >= 1`. The clamped value therefore never goes past the work area, and the centering in the caller stays non-negative. - Worked through the new test case: scale = min(1/1000, 100/100) = 0.001, which gives (1, 0.1) and then (1, 1) after the clamp. That matches the assertion. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 00:05:28 +00:00
Marvisak commented 2026-11-25 00:06:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:02:57Z.


Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).

Clamps fitted window sizes to at least 1 pixel. The case needs a monitor work area under 2 pixels wide, which cannot occur; no value.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148080121 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/451#issuecomment-7148080121). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:02:57Z. --- Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current). Clamps fitted window sizes to at least 1 pixel. The case needs a monitor work area under 2 pixels wide, which cannot occur; no value. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!451
No description provided.