Skip to content

Winit renderer initialisation cleanup #2651

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

Merged
merged 3 commits into from
Apr 27, 2023

Conversation

tronical
Copy link
Member

Prepare for the situation where creating a renderer may fail.

Replace qualifier with use.
The creation of the renderer might fail, for example if we tried to
create an OpenGL renderer on a display that doesn't support OpenGL. We
should catch that in the future and fall back to the software renderer.
@tronical tronical requested a review from ogoffart April 27, 2023 14:33
Comment on lines 132 to 141
let platform_error: Cell<Option<PlatformError>> = Default::default();
let mut renderer: once_cell::unsync::OnceCell<Renderer> = Default::default();

match Renderer::new(&(self_weak.clone() as _)) {
Ok(new_renderer) => {
renderer = once_cell::unsync::OnceCell::with_value(new_renderer)
}
Err(err) => platform_error.set(Some(err)),
};

Copy link
Member Author

@tronical tronical Apr 27, 2023

Choose a reason for hiding this comment

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

This is annoyingly ugly, largely AFAICS because the renderer's need a dyn crate::window::WindowAdapter eventually. This includes the public SoftwareRenderer::new() API.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, i'm afraid this is the only way for now.
rust-lang/libs-team#90

One think that can a bit be improved would be to move the platform_error in the parent scope instead of in the Rc itself.
(See the code example in rust-lang/libs-team#90 (comment) )

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes, that would be nice. But then all the WinitWindowAdapter would have to support Default, i.e. corelib::api::Window have to go into a OnceCell. I'll give it a try to see how bad the code becomes - if too bad then I'll stick with this version.

Instead leave it out and return Default::default() in Rc::new_cyclic().

The map state handling gets quite ugly, because it needs to go into a OnceCell. On the upside, if we succeed with creating the winit window
in new() in the future, then that entire cell goes away.
@tronical tronical merged commit 2b45f94 into master Apr 27, 2023
@tronical tronical deleted the simon/winit-renderer-new-cleanup branch April 27, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants