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

Don't panic when wgpu swapchain frame is outdated #667

Merged
merged 8 commits into from
Aug 5, 2021
Merged

Don't panic when wgpu swapchain frame is outdated #667

merged 8 commits into from
Aug 5, 2021

Conversation

BillyDM
Copy link

@BillyDM BillyDM commented Dec 16, 2020

The compositor in iced_wgpu should not panic when the wgpu swapchain returns an outdated error, which can happen when the window is resized. Instead, simply try drawing again the next frame.

I haven't encountered this issue much with the winit version of iced, but it is happening consistently with my own iced_baseview backend. Could be differences in timing.

Fixes #799.

@BillyDM
Copy link
Author

BillyDM commented Dec 19, 2020

We figured out this issue is caused by the fact that X11 events are sent asynchronously. So there is no way to ensure that a resize event won't be sent during the time between MainEventsCleared and RedrawRequested. We suspect that winit's timing just makes it less likely for this race condition to occur.

We added a fix to baseview to make it less likely to happen as well, but we should still at least not panic if this situation occurs.

@PolyMeilex
Copy link
Contributor

Happen to me on winit multiple times as well, so it would be nice to get this merged

@BillyDM
Copy link
Author

BillyDM commented Feb 22, 2021

It turns out, some NVidia drivers on Linux will also panic like this right when the applications starts. This only appears to happen when the window is a parented window, such as audio plugins made with iced_baseview.

Copy link
Member

@derezzedex derezzedex left a comment

Choose a reason for hiding this comment

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

I've left some suggestions, aside from that, looks great. Good job!

Comment on lines 222 to 226
wgpu::SwapChainError::Outdated => {
// Try rendering again next frame.
window.request_redraw();
}
_ => panic!("Swapchain error: {:?}", error),
Copy link
Member

Choose a reason for hiding this comment

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

Can we handle the other errors? I think the only error that makes sense to panic is OutOfMemory.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, this makes sense.

@@ -49,5 +52,5 @@ pub trait Compositor: Sized {
background_color: Color,
output: &<Self::Renderer as iced_native::Renderer>::Output,
overlay: &[T],
) -> mouse::Interaction;
) -> Result<mouse::Interaction, ()>;
Copy link
Member

Choose a reason for hiding this comment

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

I think a proper error type here would make sense, maybe just copy SwapChainError.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe? I think that the SwapChainError is only specific to wgpu though.

Copy link
Author

Choose a reason for hiding this comment

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

Actually, yeah that could work. I've made those changes.

@hecrj hecrj added the bug Something isn't working label Aug 4, 2021
@hecrj hecrj added this to the 0.4.0 milestone Aug 4, 2021
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

Looks great @BillyDM! And great suggestions, @derezzedex.

Thank you both and sorry for the wait! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes when moving workspaces in bspwm
4 participants