Skip to content

Change RawHandleWrapper so that we can create it #15380

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

Closed
wants to merge 1 commit into from

Conversation

Jakkestt
Copy link

Objective

The winit windowing backend does not require a mutable reference to the window to be able to change it. For example you can set the window fullscreen or change the title without needing a mutable reference. The same cannot be said for other windowing backends like glfw. This becomes a problem when, to create a WindowWrapper, you need to give it ownership of the window. And you need a WindowWrapper to create a RawHandleWrapper which you need to render things to the window. There doesn't seem to be any reason to give ownership of the window to the WindowWrapper, but in doing so, there is no easy way of getting a mutable reference to the window anymore.

Solution

The solution that I came to was to remove _window field from the RawHandleWrapper so that I could construct a RawHandleWrapper without needing to give ownership of the window itself. I don't know what the _window field did, but removing it didn't seem to do anything.

Testing

I ran a window_resizing example and 2d_shapes example and they both ran well enough. I didn't really change much and I think that any errors should have been caught when building the engine.

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 A-Windowing Platform-agnostic interface layer to run your app in C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 23, 2024
@alice-i-cecile alice-i-cecile requested a review from hymm September 23, 2024 03:03
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Sep 23, 2024
@alice-i-cecile
Copy link
Member

I'm pretty sure the _window marker is to mark the resource as !Send, but that's a very weird way to do it. What does the commit history say?

@hymm
Copy link
Contributor

hymm commented Sep 23, 2024

It's needed to drop the window at the correct time. See this comment on window wrapper. https://docs.rs/bevy/latest/bevy/window/struct.WindowWrapper.html

@Friz64
Copy link
Contributor

Friz64 commented Sep 23, 2024

Hello, I came up with this wrapper.

This becomes a problem when, to create a WindowWrapper, you need to give it ownership of the window. And you need a WindowWrapper to create a RawHandleWrapper which you need to render things to the window.

This is very much by design. If you want a mutable reference to the inner window, you're gonna need to use a Mutex (or similar). I know it's ugly. Sorry.

@Jakkestt
Copy link
Author

Hello, I came up with this wrapper.

This becomes a problem when, to create a WindowWrapper, you need to give it ownership of the window. And you need a WindowWrapper to create a RawHandleWrapper which you need to render things to the window.

This is very much by design. If you want a mutable reference to the inner window, you're gonna need to use a Mutex (or similar). I know it's ugly. Sorry.

And how exactly would I do that?

@alice-i-cecile alice-i-cecile removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Sep 23, 2024
@alice-i-cecile
Copy link
Member

Closing this out, but do continue discussing workarounds and alternatives: this is something that would be nice to ensure is possible.

@Friz64
Copy link
Contributor

Friz64 commented Sep 23, 2024

@Jakkestt Hmm, you're right, it's not as straightforward as I thought. The thing is that winit makes all this very easy for us. On top of their Window type only having "immutable" methods, it also implements Send + Sync, unlike GLFW's window. It's definitely possible to cook something up that'll work, but you'll need some carefully considered unsafe blocks. If you want to, you can contact me on Discord (friz64) or Matrix (@Friz64:gitter.im) for help brainstorming a good solution for your case.

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-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants