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

Allow Bevy to start from non-main threads on supported platforms #10020

Merged
merged 7 commits into from
Oct 6, 2023

Conversation

torsteingrindvik
Copy link
Contributor

@torsteingrindvik torsteingrindvik commented Oct 4, 2023

Objective

Allow Bevy apps to run without requiring to start from the main thread.
This allows other projects and applications to do things like spawning a normal or scoped
thread and run Bevy applications there.

The current behaviour if you try this is a panic.

Solution

Allow this by default on platforms winit supports this behaviour on (x11, Wayland, Windows).


Changelog

Added

  • Added the ability to start Bevy apps outside of the main thread on x11, Wayland, Windows

@torsteingrindvik torsteingrindvik added the A-Windowing Platform-agnostic interface layer to run your app in label Oct 4, 2023
Comment on lines 81 to 82
// This is needed because the X11 feature
// might be enabled for macos too.
Copy link
Member

Choose a reason for hiding this comment

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

not just on macOS, x11 is enabled by default in Bevy on all platforms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, new comment is hopefully more correct

Signed-off-by: Torstein Grindvik <[email protected]>
@hymm
Copy link
Contributor

hymm commented Oct 4, 2023

can you add this for windows too?

Signed-off-by: Torstein Grindvik <[email protected]>
@torsteingrindvik
Copy link
Contributor Author

can you add this for windows too?

Added.

Missed it because for me, https://docs.rs/winit/latest/winit/?search=any_thread does not show Windows 🤔
But I see it in the source.

@maniwani
Copy link
Contributor

maniwani commented Oct 4, 2023

Yeah, this looks good. Just, users need to make sure any non-send resources get initialized in the same thread the app will live in (i.e. construct the app inside the new thread, don't add plugins in the main thread and then move it there).

@mockersf
Copy link
Member

mockersf commented Oct 4, 2023

I don't have any of the platforms impacted, but it should work as long as winit works 👍

I think it should be configurable by the user

@torsteingrindvik
Copy link
Contributor Author

I don't have any of the platforms impacted, but it should work as long as winit works 👍

I think it should be configurable by the user

I initially thought to make it configurable, but then I realized it only enables more flexiblity for the users of the affected platforms.

Since as far as I can tell it has no downsides, I see no point in not allowing any thread to start Bevy on platforms which support it.

Happy to make it configurable if you want to, in that case could you let me know which way to go:

  1. Feature flag
  2. A resource
  3. A field on the winit plugin
  4. Something else?

@JMS55
Copy link
Contributor

JMS55 commented Oct 5, 2023

Imo this should be off by default, because a user may not realize that it works only on the platform they're developing on, and then run into issues later when running on a different platform.

I'm in favor of a field on the winit plugin.

Signed-off-by: Torstein Grindvik <[email protected]>
@torsteingrindvik
Copy link
Contributor Author

Imo this should be off by default, because a user may not realize that it works only on the platform they're developing on, and then run into issues later when running on a different platform.

I'm in favor of a field on the winit plugin.

Good point, changed to this behavior now.

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 5, 2023
crates/bevy_winit/src/lib.rs Outdated Show resolved Hide resolved
auto-merge was automatically disabled October 6, 2023 10:48

Head branch was pushed to by a user without write access

@torsteingrindvik
Copy link
Contributor Author

@james7132 there was some issues with docs, so changed the doc link slightly but kept it to local symbols.

@mockersf mockersf added this pull request to the merge queue Oct 6, 2023
Merged via the queue into bevyengine:main with commit 8b21ee4 Oct 6, 2023
21 checks passed
@cart cart mentioned this pull request Oct 13, 2023
43 tasks
regnarock pushed a commit to regnarock/bevy that referenced this pull request Oct 13, 2023
…yengine#10020)

# Objective

Allow Bevy apps to run without requiring to start from the main thread.
This allows other projects and applications to do things like spawning a
normal or scoped
thread and run Bevy applications there.

The current behaviour if you try this is a panic.

## Solution

Allow this by default on platforms winit supports this behaviour on
(x11, Wayland, Windows).

---

## Changelog

### Added

- Added the ability to start Bevy apps outside of the main thread on
x11, Wayland, Windows

---------

Signed-off-by: Torstein Grindvik <[email protected]>
Signed-off-by: Torstein Grindvik <[email protected]>
Co-authored-by: Torstein Grindvik <[email protected]>
Co-authored-by: James Liu <[email protected]>
ameknite pushed a commit to ameknite/bevy that referenced this pull request Nov 6, 2023
…yengine#10020)

# Objective

Allow Bevy apps to run without requiring to start from the main thread.
This allows other projects and applications to do things like spawning a
normal or scoped
thread and run Bevy applications there.

The current behaviour if you try this is a panic.

## Solution

Allow this by default on platforms winit supports this behaviour on
(x11, Wayland, Windows).

---

## Changelog

### Added

- Added the ability to start Bevy apps outside of the main thread on
x11, Wayland, Windows

---------

Signed-off-by: Torstein Grindvik <[email protected]>
Signed-off-by: Torstein Grindvik <[email protected]>
Co-authored-by: Torstein Grindvik <[email protected]>
Co-authored-by: James Liu <[email protected]>
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
…yengine#10020)

# Objective

Allow Bevy apps to run without requiring to start from the main thread.
This allows other projects and applications to do things like spawning a
normal or scoped
thread and run Bevy applications there.

The current behaviour if you try this is a panic.

## Solution

Allow this by default on platforms winit supports this behaviour on
(x11, Wayland, Windows).

---

## Changelog

### Added

- Added the ability to start Bevy apps outside of the main thread on
x11, Wayland, Windows

---------

Signed-off-by: Torstein Grindvik <[email protected]>
Signed-off-by: Torstein Grindvik <[email protected]>
Co-authored-by: Torstein Grindvik <[email protected]>
Co-authored-by: James Liu <[email protected]>
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 S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants