Skip to content

Conversation

@eero-lehtinen
Copy link
Contributor

@eero-lehtinen eero-lehtinen commented Oct 28, 2024

Objective

When the wayland feature is not enabled, xwayland is used on wayland. Nvidia drivers are somewhat bugged on linux and return outdated surfaces on xwayland for seemingly no reason. Oftentimes at startup we get into an infine loop where the surface is permanently outdated and nothing (or sometimes only the first frame) is drawn on the screen.

Solution

After experimenting I found that we can safely call configure again and the issue seems to resolve itsef. After this change I couldn't reproduce the original issue after many tries. More testing is probably needed though.

The main issue is that get_current_texture fails sometimes because the surface remains outdated even after configuring. It would be better to just properly handle and never panic when get_current_texture fails. This way we always call configure when outdated and bail when getting the swapchain fails instead of crashing. The number of special cases is also reduced.

Testing

I tested the example "rotation" manually by trying to move around.

It works with X11 and Xwayland and the non panicing code paths didn't change so other platforms aren't affected.

This seems to prevent the whole screen from freezing at startup
when using using xwayland and nvidia.
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Testing A change that impacts how we test Bevy or how users test their apps labels Oct 28, 2024
@alice-i-cecile
Copy link
Member

@Frost2779 can you test this for me? This should help with what you were seeing in #16120.

@alice-i-cecile alice-i-cecile added O-Linux Specific to the Linux desktop operating system S-Needs-Testing Testing must be done before this is safe to merge and removed C-Testing A change that impacts how we test Bevy or how users test their apps labels Oct 28, 2024
@BenjaminBrienen BenjaminBrienen added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Oct 28, 2024
@Frost2779
Copy link

@alice-i-cecile I tested with the MRE from the original issue thread with 10 separate launches and did not encounter the unexpected behavior. Sprite rendered and systems seemed to function as expected.

@bas-ie
Copy link
Contributor

bas-ie commented Oct 28, 2024

@alice-i-cecile I tested with the MRE from the original issue thread with 10 separate launches and did not encounter the unexpected behavior. Sprite rendered and systems seemed to function as expected.

Just out of curiosity, did you test with wayland feature on or off?

@eero-lehtinen
Copy link
Contributor Author

eero-lehtinen commented Oct 28, 2024

I don't really get why we even have this if-else here when the two cases are identical except the else case handles extra stuff that already never happens in the first.

#12542 here I also wanted to remove the if-else but didn't because people didn't want to review too much code, but I really do think it's better that way.

render_device.configure_surface(&data.surface, &data.configuration);
}

window_surfaces.configured_windows.insert(window.entity);
Copy link
Contributor Author

@eero-lehtinen eero-lehtinen Oct 28, 2024

Choose a reason for hiding this comment

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

Marking windows configured fits better after configuring them instead of in the next system where they are configured only when outdated. The configured_windows is only used in this system and its condition now.

Err(err) => {
// This is a common occurrence on X11 and Xwayland with NVIDIA drivers
// when opening and resizing the window.
warn!("Couldn't get swap chain texture after configuring. Cause: '{err}'");
Copy link
Member

@tychedelia tychedelia Oct 28, 2024

Choose a reason for hiding this comment

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

By removing the is_nvidia and linux cfg, this now means we don't panic on other platforms where we did before. The removal of the duplication seems to make sense to me, but I'm unsure (as in legitimately don't know) about making this change across all platforms rather than just targeting linux. Would like to better understand the history here.

Copy link
Contributor Author

@eero-lehtinen eero-lehtinen Oct 28, 2024

Choose a reason for hiding this comment

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

We don't have any platforms that instantly panic with an outdated surface, so this doesn't functionally change anything. Also it is better to handle errors instead of just panicing in general, clearly just having an outdated surface isn't fatal. It's also completely possible that some other platform also returns an error here in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, that's good enough for me. Thanks!

@eero-lehtinen
Copy link
Contributor Author

I don't really get why we even have this if-else here when the two cases are identical except the else case handles extra stuff that already never happens in the first.

#12542 here I also wanted to remove the if-else but didn't because people didn't want to review too much code, but I really do think it's better that way.

It looks like here https://github.com/bevyengine/bevy/pull/12055/files#diff-b0a34efd7fd2e03ca78f181d1ecce355b927f07669a75501af11498f8b9ec3adL343 we did something extra in the if statement, but now it's not useful anymore.

@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-Testing Testing must be done before this is safe to merge labels Oct 28, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Oct 28, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 28, 2024
Merged via the queue into bevyengine:main with commit af27907 Oct 28, 2024
30 checks passed
mockersf pushed a commit that referenced this pull request Nov 5, 2024
# Objective

- Fixes #16122

When the wayland feature is not enabled, xwayland is used on wayland.
Nvidia drivers are somewhat bugged on linux and return outdated surfaces
on xwayland for seemingly no reason. Oftentimes at startup we get into
an infine loop where the surface is permanently outdated and nothing (or
sometimes only the first frame) is drawn on the screen.

## Solution

After experimenting I found that we can safely call configure again and
the issue seems to resolve itsef. After this change I couldn't reproduce
the original issue after many tries. More testing is probably needed
though.

The main issue is that `get_current_texture` fails sometimes because the
surface remains outdated even after configuring. It would be better to
just properly handle and never panic when `get_current_texture` fails.
This way we always call configure when outdated and bail when getting
the swapchain fails instead of crashing. The number of special cases is
also reduced.

## Testing

I tested the example "rotation" manually by trying to move around.

It works with X11 and Xwayland and the non panicing code paths didn't
change so other platforms aren't affected.
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 C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples O-Linux Specific to the Linux 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.

NVIDIA drivers on Linux can cause an intermittent failure to render under X11

6 participants