Skip to content

Fix window resize stretching the canvas instead of resizing the sketch surface (#127)#170

Merged
catilac merged 13 commits into
processing:mainfrom
arrxy:main
Jun 30, 2026
Merged

Fix window resize stretching the canvas instead of resizing the sketch surface (#127)#170
catilac merged 13 commits into
processing:mainfrom
arrxy:main

Conversation

@arrxy

@arrxy arrxy commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fix: #127

Both bugs stem from the same root confusion: logical vs. physical pixels. @catilac

Summary

Two rendering issues with a shared cause in how window dimensions were
interpreted.

Fix 1 Resize stretched the canvas instead of reflowing it

Root cause: Bevy's WinitPlugin is disabled (we use a GLFW backend), so
nothing emitted WindowResized. Without that event:

  • bevy_render's camera_system never ran on resize
  • the camera's Projection stayed pinned to the original size
  • the render target was simply scaled to fit — the "stretch"
  • width/height (SurfaceSize) were left stale

Fix: input_window_resize now emits WindowResized itself whenever a window's
physical size actually changes.

Fix 2 macOS Retina rendered 400×400 sketches as 800×800

Root cause: the camera's ProcessingProjection (the sketch's coordinate
space) was built from physical dimensions (width × scale_factor = 800 on a
2× display) instead of the logical size (400), doubling everything.

Fix: use logical width/height for the projection and SurfaceSize;
reserve physical dimensions for the GPU texture (Extent3d) and readback buffer
only.

@arrxy arrxy marked this pull request as ready for review June 25, 2026 22:43
@catilac catilac requested review from catilac and tychedelia June 29, 2026 15:33

@catilac catilac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good! I've left some questions if you could answer before i merge this in

@@ -118,6 +118,8 @@ impl CameraProjection for ProcessingProjection {
// this gets called with the render target's physical dimensions (i.e. accounting for
// scale factor), but our projection is in logical pixel units
// TODO: handle resizes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like this TODO can be removed :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

mut windows: Query<&mut Window>,
mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize)>,
) -> Result<()> {
let width = width.max(1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so width and height are clamped between 0 and 1?

@arrxy arrxy Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

let width = width.max(1);
This is width = max(width, 1), as 0 or negative width and height are not handled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@arrxy i'm asking about 1. what is the significance there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ohh I put the min limit 1, so that the box cannot be shrinked to nothing.

@arrxy arrxy requested a review from catilac June 29, 2026 19:16
@catilac catilac merged commit fafd368 into processing:main Jun 30, 2026
4 checks passed
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.

Window resize stretches canvas instead of resizing sketch surface

2 participants