Skip to content

Comments

Desktop: Make shutdown more robust and fix panic caused by invalid viewport scale#3783

Merged
TrueDoctor merged 2 commits intomasterfrom
fix-zero-size-viewport-crash
Feb 22, 2026
Merged

Desktop: Make shutdown more robust and fix panic caused by invalid viewport scale#3783
TrueDoctor merged 2 commits intomasterfrom
fix-zero-size-viewport-crash

Conversation

@timon-schelling
Copy link
Member

@timon-schelling timon-schelling commented Feb 18, 2026

fixes

thread 'main' (6871) panicked at editor/src/messages/viewport/viewport_message_handler.rs:526:5:
assertion `left == right` failed: Cannot multiply with diffent scale
  left: NaN
 right: NaN

Re-fixes #3514.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a panic caused by an invalid viewport scale (NaN). The changes introduce checks in both the Rust backend and the TypeScript frontend to validate the scale value. While the fix is correct for the reported issue, my review includes suggestions to make these checks more robust by also handling non-finite values like Infinity, which could cause similar problems. I've recommended using is_finite() in Rust and Number.isFinite() in TypeScript for more comprehensive validation.

match message {
ViewportMessage::Update { x, y, width, height, scale } => {
assert_ne!(scale, 0., "Viewport scale cannot be zero");
assert!(scale > 0., "Viewport scale must be greater than zero");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly prevents NaN scale values which caused the original panic, it still allows Infinity. An infinite scale could be passed from the frontend and lead to other calculations resulting in Infinity or NaN, potentially causing other issues. Using is_finite() would make this assertion more robust.

Suggested change
assert!(scale > 0., "Viewport scale must be greater than zero");
assert!(scale.is_finite() && scale > 0., "Viewport scale must be finite and greater than zero");

Comment on lines +45 to +47
if (!scale || scale <= 0) {
continue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check !scale works for NaN and 0, but using Number.isFinite() is more explicit and robust. It will correctly handle Infinity, -Infinity, and NaN, which can occur if logicalWidth is zero. This ensures that only valid, finite, positive scale values are sent to the backend.

Suggested change
if (!scale || scale <= 0) {
continue;
}
if (!Number.isFinite(scale) || scale <= 0) {
continue;
}

@GraphiteEditor GraphiteEditor deleted a comment from gemini-code-assist bot Feb 18, 2026
@timon-schelling timon-schelling changed the title Fix panic caused by invalid viewport scale Desktop: Make shutdown more robust and fix panic caused by invalid viewport scale Feb 18, 2026
@Keavon
Copy link
Member

Keavon commented Feb 22, 2026

This fixes slow shutdown on Windows as well as stuttery window minimization.

@TrueDoctor TrueDoctor added this pull request to the merge queue Feb 22, 2026
Merged via the queue into master with commit a2d3b3f Feb 22, 2026
4 checks passed
@TrueDoctor TrueDoctor deleted the fix-zero-size-viewport-crash branch February 22, 2026 17:49
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.

On Windows desktop, closing the app takes several seconds

3 participants