Guard capture allocations against impossible frame sizes #1033

Open
superboynick wants to merge 3 commits from upstream-pr/1035 into main
superboynick commented 2026-11-25 16:57:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by superboynick on 2026-11-25T16:57:41Z.


On a 4K-window machine, turning frame capture on killed the process before the first frame:

memory allocation of 7763201452000 bytes failed

The size came from unchecked multiplication of the presented width and height. This computes it with checked arithmetic, caps a single frame buffer at 512 MiB, and on failure warns once with the dimensions and the estimate, then disables capture and keeps presenting. Capture-off behaviour is untouched.

Tests. The decision is now a pure predicate over the estimated size, with cases that state the rule: 1080p and 4K fit, exactly at the ceiling fits, one byte over does not, a 64K square does not, and the multiplication that produced the 7.7 TB request overflows to None instead of wrapping. cargo test -p victory-gpu: 170 passed, 5 ignored.

Verified on two machines: an RTX 5070 Ti at 1920x1080 (capture off: process alive, ~4170 log lines; capture on: alive, 12 PNGs written) and an RTX 3080 Ti at 3840x2160, where the old build died in the allocator and the new one writes capture frames.

Not claimed: this hardens the capture path rather than explaining why the harness reported those dimensions; the warning now prints width, height and estimate so the next occurrence is self-explanatory.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6609461012 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1035). Originally posted by [superboynick](https://github.com/superboynick) on 2026-11-25T16:57:41Z. --- On a 4K-window machine, turning frame capture on killed the process before the first frame: ` memory allocation of 7763201452000 bytes failed ` The size came from unchecked multiplication of the presented width and height. This computes it with checked arithmetic, caps a single frame buffer at 512 MiB, and on failure warns once with the dimensions and the estimate, then disables capture and keeps presenting. Capture-off behaviour is untouched. **Tests.** The decision is now a pure predicate over the estimated size, with cases that state the rule: 1080p and 4K fit, exactly at the ceiling fits, one byte over does not, a 64K square does not, and the multiplication that produced the 7.7 TB request overflows to `None` instead of wrapping. `cargo test -p victory-gpu`: 170 passed, 5 ignored. **Verified on two machines:** an RTX 5070 Ti at 1920x1080 (capture off: process alive, ~4170 log lines; capture on: alive, 12 PNGs written) and an RTX 3080 Ti at 3840x2160, where the old build died in the allocator and the new one writes capture frames. **Not claimed:** this hardens the capture path rather than explaining why the harness reported those dimensions; the warning now prints width, height and estimate so the next occurrence is self-explanatory.
superboynick commented 2026-11-25 18:05:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by superboynick on 2026-11-25T17:09:22Z.


Follow-up available in the same fork: a stacked change that adds VICTORY_CAPTURE_AT (comma-separated seconds from the first present, writes frame-at-<t>.png) so captures line up across machines regardless of frame rate - https://github.com/superboynick/victory-fork/pull/1 . It depends on this guard, which is why it targets this branch rather than main. Happy to fold both into a single change if you prefer to review them together.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7169087805 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1035#issuecomment-7169087805). Originally posted by [superboynick](https://github.com/superboynick) on 2026-11-25T17:09:22Z. --- Follow-up available in the same fork: a stacked change that adds `VICTORY_CAPTURE_AT` (comma-separated seconds from the first present, writes `frame-at-<t>.png`) so captures line up across machines regardless of frame rate - https://github.com/superboynick/victory-fork/pull/1 . It depends on this guard, which is why it targets this branch rather than `main`. Happy to fold both into a single change if you prefer to review them together.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1035:upstream-pr/1035'
git switch 'upstream-pr/1035'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1035'
git switch 'upstream-pr/1035'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1035'
git switch 'upstream-pr/1035'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1035'
git switch 'main'
git merge --squash 'upstream-pr/1035'
git switch 'main'
git merge --ff-only 'upstream-pr/1035'
git switch 'main'
git merge 'upstream-pr/1035'
git push origin 'main'
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
fxceless/victory-fork!1033
No description provided.