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 surface validation errors in WSL2 environments during window resizing #18246

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tyler274
Copy link

@tyler274 tyler274 commented Mar 10, 2025

This is a known issue with Vulkan surface compatibility in WSL2 environments during window resizing operations.

Solution

I've implemented a solution that gracefully handles these WSL2-specific surface errors:

  1. Added a function to detect if the application is running in a WSL2 environment by checking OS-specific identifiers in /proc/sys/kernel/osrelease.
  2. Created a helper function that safely captures and handles surface configuration panics in WSL2 environments, allowing applications to continue running instead of crashing.
  3. Modified the surface configuration logic to use this safer approach when running in WSL.
  4. Added specific error handling for WSL-related surface errors that provides informative warning messages.

The implementation is non-intrusive and only activates the special error handling in WSL environments, with no impact on other platforms.

Testing

I've tested these changes by:

  1. Running the test suite, which passes with all tests succeeding

I need to test:
2. Testing window resizing in a WSL2 environment that previously crashed
3. Verifying that there's no impact on non-WSL environments

This PR doesn't introduce any breaking changes and only adds graceful error handling to improve the user experience in WSL2 environments.

Showcase

Before this change, attempting to resize a window in WSL2 would cause the entire application to crash with the error message shown above. After this change, the application continues running with a warning message, and while there may be temporary visual glitches during resizing, the application remains stable and functional.

This is particularly helpful for developers who use WSL2 for their Bevy development workflow.

Copy link
Contributor

Welcome, new contributor!

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

@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 O-Linux Specific to the Linux desktop operating system O-Windows Specific to the Windows desktop operating system S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Mar 11, 2025
@aloucks
Copy link
Contributor

aloucks commented Mar 11, 2025

Are you using llvmpipe or the experimental Dozen mesa d3d12 backend? Or something else?

When using llvmpipe, I'll get validation errors but it doesn't crash.

2025-03-11T22:49:08.908121Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (Ubuntu 22.04)", kernel: "5.15.167.4-microsoft-standard-WSL2", cpu: "Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz", core_count: "8", memory: "15.5 GiB" }
2025-03-11T22:49:12.964722Z  INFO bevy_render::renderer: AdapterInfo { name: "llvmpipe (LLVM 15.0.7, 256 bits)", vendor: 65541, device: 0, device_type: Cpu, driver: "llvmpipe", driver_info: "Mesa 23.2.1-1ubuntu3.1~22.04.3 (LLVM 15.0.7)", backend: Vulkan }

If I use Dozen, everything just works. I don't even get validation errors when resizing. I had to compile mesa from scratch though to get this working.

2025-03-11T22:51:33.064508Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (Ubuntu 22.04)", kernel: "5.15.167.4-microsoft-standard-WSL2", cpu: "Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz", core_count: "8", memory: "15.5 GiB" }
2025-03-11T22:51:33.072363Z  WARN winit::platform_impl::linux::x11::xdisplay: error setting XSETTINGS; Xft options won't reload automatically
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
WARNING: dzn is not a conformant Vulkan implementation, testing use only.
2025-03-11T22:51:36.078912Z  INFO bevy_render::renderer: AdapterInfo { name: "Microsoft Direct3D12 (NVIDIA GeForce RTX 2060)", vendor: 4318, device: 7944, device_type: DiscreteGpu, driver: "Dozen", driver_info: "Mesa 25.1.0-devel (git-551770ccf8)", backend: Vulkan }

I have to set the allow noncomplient adapter for Dozen. It doesn't report the API version correctly for me.

.add_plugins(DefaultPlugins.set(RenderPlugin {
    render_creation: RenderCreation::Automatic(WgpuSettings {
        instance_flags: InstanceFlags::ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER,
        ..default()
    }),
    ..default()
}))

Are you using X11 or Wayland? Wayland is super buggy for me in WSL2 (at least when using WGPU/Winit/Bevy)

@tyler274
Copy link
Author

tyler274 commented Mar 11, 2025 via email

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 O-Linux Specific to the Linux desktop operating system O-Windows Specific to the Windows desktop operating system S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants