Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Skip some rendering logics when the viewport width or height is zero #15654

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

ShoyuVanilla
Copy link
Contributor

@ShoyuVanilla ShoyuVanilla commented Oct 4, 2024

Objective

Solution

winit sends resized to zero events when the window is minimized only on Windows OS(rust-windowing/winit#2015).
This makes updating window viewport size to (0, 0) and panicking when calculating aspect ratio.

So, just skip these kinds of events - resizing to (0, 0) when the window is minimized - on Windows OS

Idially, the camera extraction excludes the cameras whose target size width or height is zero here;

if let (
Some(URect {
min: viewport_origin,
..
}),
Some(viewport_size),
Some(target_size),
) = (
camera.physical_viewport_rect(),
camera.physical_viewport_size(),
camera.physical_target_size(),
) {
if target_size.x == 0 || target_size.y == 0 {
continue;
}

but it seems that winit event loop sends resize events after extraction and before post update schedule, so they might panics before the extraction filters them out.

Alternatively, it might be possible to change event loop evaluating order or defer them to the right schedule but I'm afraid that it might cause some breaking changes, so just skip rendering logics for such windows and they will be all filtered out by the extractions on the next frame and thereafter.

Testing

Running the example in the original issue and minimizing causes panic, or just running tests/window/minimising.rs with cargo run --example minimising panics without this PR and doesn't panics with this PR.

I think that we should run it in CI on Windows OS btw

Copy link
Contributor

github-actions bot commented Oct 4, 2024

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@JMS55 JMS55 added this to the 0.15 milestone Oct 4, 2024
@mockersf
Copy link
Member

mockersf commented Oct 4, 2024

This works by hiding the problem.

Would it be possible to stop rendering when the render target is (0,0)? I think this was done in a few places already

@IQuick143 IQuick143 added A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in O-Windows Specific to the Windows desktop operating system D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 4, 2024
@ShoyuVanilla
Copy link
Contributor Author

This works by hiding the problem.

Would it be possible to stop rendering when the render target is (0,0)? I think this was done in a few places already

Okay, I'll look into this more

@ShoyuVanilla ShoyuVanilla changed the title fix: Ignore window resized to (0, 0) events when minimizing window on Windows OS fix: Skip some rendering logics when the viewport width or height is zero Oct 5, 2024
@ShoyuVanilla
Copy link
Contributor Author

I've changed the approach

Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

Simple change well executed!

Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

This might be off base or incur other kinds of sneaky bugs in the future, but I'm wondering if the methods on camera shouldn't check and return None in the case of (0,0), is this ever a valid size that code would want to support? I guess None is different than zero sized in the context of viewports, but for some reason I feel like we should try for a fix upstream rather than hard coding the 0 checks everywhere (which will surely also be forgotten in the future).

@ShoyuVanilla
Copy link
Contributor Author

This might be off base or incur other kinds of sneaky bugs in the future, but I'm wondering if the methods on camera shouldn't check and return None in the case of (0,0), is this ever a valid size that code would want to support? I guess None is different than zero sized in the context of viewports, but for some reason I feel like we should try for a fix upstream rather than hard coding the 0 checks everywhere (which will surely also be forgotten in the future).

On the None for viewport (0, 0), I think that it seems reasonable to do so, but I'm not so confident about it because I'm quite new to bevy 😅
In general, I agree with that the issues caused from the upstreams should be fixed from the upstream.
But I think that it's also worthwhile to handle zero-sized viewport because it might be happen by window resizing or something, other than minimizing on Windows OS. (Of course it should be better than the current hard coded way)

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 8, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 8, 2024
Merged via the queue into bevyengine:main with commit a89ae8e Oct 8, 2024
27 checks passed
@ShoyuVanilla ShoyuVanilla deleted the issue-15285 branch October 8, 2024 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in D-Straightforward Simple bug fixes and API improvements, docs, test and examples O-Windows Specific to the Windows desktop operating system S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Minimizing window in the irradiance_volume example causes a crash
7 participants