Skip to content

Commit 70c69cd

Browse files
Fix crash on Linux Nvidia 550 driver (#12542)
# Objective Fix crashing on Linux with latest stable Nvidia 550 driver when resizing. The crash happens at startup with some setups. Fixes #12199 I think this would be nice to get into 0.13.1 ## Solution Ignore `wgpu::SurfaceError::Outdated` always on this platform+driver. It looks like Nvidia considered the previous behaviour of not returning this error a bug: "Fixed a bug where vkAcquireNextImageKHR() was not returning VK_ERROR_OUT_OF_DATE_KHR when it should with WSI X11 swapchains" (https://www.nvidia.com/Download/driverResults.aspx/218826/en-us/) What I gather from this is that the surface was outdated on previous drivers too, but they just didn't report it as an error. So behaviour shouldn't change. In the issue conversation we experimented with calling `continue` when this error happens, but I found that it results in some small issues like bevy_egui scale not updating with the window sometimes. Just doing nothing seems to work better. ## Changelog - Fixed crashing on Linux with Nvidia 550 driver when resizing the window ## Migration Guide --------- Co-authored-by: James Liu <contact@jamessliu.com>
1 parent 3e1c846 commit 70c69cd

File tree

1 file changed

+31
-4
lines changed
  • crates/bevy_render/src/view/window

1 file changed

+31
-4
lines changed

crates/bevy_render/src/view/window/mod.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::{
88
};
99
use bevy_app::{App, Plugin};
1010
use bevy_ecs::{entity::EntityHashMap, prelude::*};
11+
#[cfg(target_os = "linux")]
12+
use bevy_utils::warn_once;
1113
use bevy_utils::{default, tracing::debug, HashSet};
1214
use bevy_window::{
1315
CompositeAlphaMode, PresentMode, PrimaryWindow, RawHandleWrapper, Window, WindowClosed,
@@ -216,6 +218,9 @@ impl WindowSurfaces {
216218
}
217219
}
218220

221+
#[cfg(target_os = "linux")]
222+
const NVIDIA_VENDOR_ID: u32 = 0x10DE;
223+
219224
/// (re)configures window surfaces, and obtains a swapchain texture for rendering.
220225
///
221226
/// NOTE: `get_current_texture` in `prepare_windows` can take a long time if the GPU workload is
@@ -304,19 +309,41 @@ pub fn prepare_windows(
304309
})
305310
};
306311

312+
#[cfg(target_os = "linux")]
313+
let is_nvidia = || {
314+
render_instance
315+
.enumerate_adapters(wgpu::Backends::VULKAN)
316+
.iter()
317+
.any(|adapter| adapter.get_info().vendor & 0xFFFF == NVIDIA_VENDOR_ID)
318+
};
319+
307320
let not_already_configured = window_surfaces.configured_windows.insert(window.entity);
308321

309322
let surface = &surface_data.surface;
310323
if not_already_configured || window.size_changed || window.present_mode_changed {
311-
let frame = surface
312-
.get_current_texture()
313-
.expect("Error configuring surface");
314-
window.set_swapchain_texture(frame);
324+
match surface.get_current_texture() {
325+
Ok(frame) => window.set_swapchain_texture(frame),
326+
#[cfg(target_os = "linux")]
327+
Err(wgpu::SurfaceError::Outdated) if is_nvidia() => {
328+
warn_once!(
329+
"Couldn't get swap chain texture. This often happens with \
330+
the NVIDIA drivers on Linux. It can be safely ignored."
331+
);
332+
}
333+
Err(err) => panic!("Error configuring surface: {err}"),
334+
};
315335
} else {
316336
match surface.get_current_texture() {
317337
Ok(frame) => {
318338
window.set_swapchain_texture(frame);
319339
}
340+
#[cfg(target_os = "linux")]
341+
Err(wgpu::SurfaceError::Outdated) if is_nvidia() => {
342+
warn_once!(
343+
"Couldn't get swap chain texture. This often happens with \
344+
the Nvidia 550 driver. It can be safely ignored."
345+
);
346+
}
320347
Err(wgpu::SurfaceError::Outdated) => {
321348
render_device.configure_surface(surface, &surface_data.configuration);
322349
let frame = surface

0 commit comments

Comments
 (0)