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

Multiple windows example panics when closing one of the windows #11236

Closed
nicopap opened this issue Jan 6, 2024 · 6 comments · Fixed by #12978
Closed

Multiple windows example panics when closing one of the windows #11236

nicopap opened this issue Jan 6, 2024 · 6 comments · Fixed by #12978
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples O-Linux Specific to the Linux desktop operating system P-Crash A sudden unexpected crash P-Regression Functionality that used to work but no longer does. Add a test for this!
Milestone

Comments

@nicopap
Copy link
Contributor

nicopap commented Jan 6, 2024

  • Bevy version: 425570a (main as of today)
  • Linux/X11

What you did

  • Run the multiple_windows example with cargo run --example multiple_windows.

What went wrong

Closing a window results in a panic with the following error:

bevy_winit: winit event loop returned an error: os error at
cargo/registry/src/winit-0.29.9/src/platform_impl/linux/x11/mod.rs:433:
Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)

Additional information

Probably related to #10702

@nicopap nicopap added C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples A-Windowing Platform-agnostic interface layer to run your app in P-Crash A sudden unexpected crash labels Jan 6, 2024
@nicopap
Copy link
Contributor Author

nicopap commented Jan 9, 2024

I'm now getting the same error on main (06bf928) on many_foxes, but it doesn't panic.

@ghost
Copy link

ghost commented Jan 10, 2024

Same as #11150 but I don't get a panic at all. This now seems to be much easier to trigger since #10411 merged.

@ghost ghost added the O-Linux Specific to the Linux desktop operating system label Jan 10, 2024
@VitalyAnkh
Copy link
Contributor

I couldn't reproduce this on the latest main (e3126a4). After Running the multiple windows example and closing one of them, I got this:

2024-02-01T09:28:37.133424Z  INFO log: GENERAL [Loader Message (0x0)]
	      Using "NVIDIA GeForce RTX 3060 Laptop GPU" with driver: "libGLX_nvidia.so.0"    
2024-02-01T09:28:37.133429Z  INFO log: 	objects: (type: INSTANCE, hndl: 0x5614e9dd3b60, name: ?)    
2024-02-01T09:28:37.717473Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux rolling Arch Linux", kernel: "6.7.2-zen1-1-zen", cpu: "", core_count: "14", memory: "31.1 GiB" }
2024-02-01T09:28:37.758296Z  INFO bevy_winit::system: Creating new window "Second window" (4v1)
2024-02-01T09:28:37.758494Z  INFO log: Guessed window scale factor: 2    
2024-02-01T09:28:38.394059Z  INFO log: GENERAL [NVIDIA (0x4)]
	Requested image extent (2560x1440) does not match surface (2560x1468), marking swapchain out of date    
2024-02-01T09:28:38.394196Z  INFO log: 	objects: (type: SWAPCHAIN_KHR, hndl: 0x5614efebcb00, name: ?)    
2024-02-01T09:28:38.427726Z  INFO log: GENERAL [NVIDIA (0x4)]
	Requested image extent (2560x1440) does not match surface (2560x1468), marking swapchain out of date    
2024-02-01T09:28:38.427760Z  INFO log: 	objects: (type: SWAPCHAIN_KHR, hndl: 0x5614efd18020, name: ?)    
2024-02-01T09:28:49.233193Z  INFO log: GENERAL [NVIDIA (0x4)]
	Requested image extent (2560x1468) does not match surface (1920x1440), marking swapchain out of date    
2024-02-01T09:28:49.233231Z  INFO log: 	objects: (type: SWAPCHAIN_KHR, hndl: 0x5614efd18020, name: ?)    
2024-02-01T09:28:50.141623Z  INFO bevy_winit::system: Closing window 4v1
2024-02-01T09:28:50.174612Z  WARN bevy_winit: Window 4v1 is missing `Window` component, skipping event RedrawRequested
2024-02-01T09:28:50.175029Z  WARN bevy_winit: Window 4v1 is missing `Window` component, skipping event Destroyed

It seems fixed now.

@nicopap
Copy link
Contributor Author

nicopap commented Feb 1, 2024

I am still getting a panic on multiple_windows on main (e618426).

Though specifically: Only when closing "Second window" first. If I close "First window". It keeps running, but the text on the second window changes from "Second window" to "Second" and the font gets smaller.

That's what I get if I close the second window first:

ERROR log: X11 error: XError {
    description: "BadWindow (invalid Window parameter)",
    error_code: 3,
    request_code: 148,
    minor_code: 1,
}    
thread 'main' panicked at /winit-0.29.10/src/platform_impl/linux/x11/event_processor.rs:978:30:
Failed to focus input context: XError { description: "BadWindow (invalid Window parameter)", error_code: 3, request_code: 148, minor_code: 1 }

Still getting the error on many_foxes, without the panic:

ERROR bevy_winit: winit event loop returned an error: os error at /winit-0.29.10/src/platform_impl/linux/x11/mod.rs:433: Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)

@ghost
Copy link

ghost commented Feb 21, 2024

I managed to trigger something similar to this last night in a multi-window app while sending close window via keyboard(same as window close button), to the second window, in my case the application live-locked and the first window never continued rendering.

2024-02-21T18:53:26.922192Z INFO bevy_winit::system: Closing window 1v1 the last log message I ever get, after this no frame ever gets rendered again in the primary window.

Even gracefully despawning a second window causes this for me, so it's not related to sending a window close command manually as above.

@ghost ghost added this to the 0.14 milestone Feb 21, 2024
@ghost ghost added the P-Regression Functionality that used to work but no longer does. Add a test for this! label Feb 21, 2024
@williamtstanley
Copy link

I am also encountering this error in a basic "initial window" app.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

Clicking the X to close the window results in the error below:

2024-02-24T21:52:13.876644Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon Vega 10 Graphics (RADV RAVEN)", vendor: 4098, device: 5592, device_type: IntegratedGpu, driver: "radv", driver_info: "Mesa 23.3.3-manjaro1.1", backend: Vulkan }
2024-02-24T21:52:14.005388Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 23.1.3 Manjaro Linux", kernel: "6.1.69-1-MANJARO", cpu: "AMD Ryzen 7 3750H with Radeon Vega Mobile Gfx", core_count: "4", memory: "13.6 GiB" }
2024-02-24T21:52:22.077129Z  INFO bevy_window::system: No windows are open, exiting
2024-02-24T21:52:22.077582Z  INFO bevy_winit::system: Closing window 0v1
2024-02-24T21:52:22.146762Z ERROR log: X11 error: XError {
    description: "BadWindow (invalid Window parameter)",
    error_code: 3,
    request_code: 148,
    minor_code: 1,
}
2024-02-24T21:52:22.154026Z ERROR bevy_winit: winit event loop returned an error: os error at /home/travis/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.10/src/platform_impl/linux/x11/mod.rs:433: Xlib error: X error: BadWindow (invalid Window parameter) (code: 3, request code: 148, minor code: 1)

github-merge-queue bot pushed a commit that referenced this issue Apr 30, 2024
… using pipelined rendering (#12978)

# Objective

A `RawWindowHandle` is only valid as long as the window it was retrieved
from is alive. Extend the lifetime of the window, so that the
`RawWindowHandle` doesn't outlive it, and bevy doesn't crash when
closing a window a pipelined renderer is drawing to.

- Fix #11236
- Fix #11150
- Fix #11734
- Alternative to / Closes #12524

## Solution

Introduce a `WindowWrapper` that takes ownership of the window. Require
it to be used when constructing a `RawHandleWrapper`. This forces
windowing backends to store their window in this wrapper.

The `WindowWrapper` is implemented by storing the window in an `Arc<dyn
Any + Send + Sync>`.

We use dynamic dispatch here because we later want the
`RawHandleWrapper` to be able dynamically hold a reference to any
windowing backend's window.

But alas, the `WindowWrapper` itself is still practically invisible to
windowing backends, because it implements `Deref` to the underlying
window, by storing its type in a `PhantomData`.

---

## Changelog

### Added

- Added `WindowWrapper`, which windowing backends are now required to
use to store their underlying window.

### Fixed

- Fixed a safety problem which caused crashes when closing bevy windows
when using pipelined rendering.

## Migration Guide

- Windowing backends now need to store their window in the new
`WindowWrapper`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples O-Linux Specific to the Linux desktop operating system P-Crash A sudden unexpected crash P-Regression Functionality that used to work but no longer does. Add a test for this!
Projects
None yet
3 participants