-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix crash when changing viewport settings #4862
Conversation
fix works on mac - it showed the same behavior as bug1, immediate exit when recreating secondary viewport. Did no exhibit bug 2 I cannot get egui to build on linux so cannot test |
winit::event::WindowEvent::Destroyed => { | ||
log::debug!( | ||
"Received WindowEvent::Destroyed for viewport {:?}", | ||
viewport_id | ||
); | ||
if viewport_id == Some(ViewportId::ROOT) { | ||
return EventResult::Exit; | ||
} else { | ||
return EventResult::Wait; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to add the same code to wgpu_integration.rs
.
We just merged the update to latest winit
(#4849), so please merge that into this branch and then test this PR with:
cargo r -p test_viewports
cargo r -p test_viewports -F wgpu
cargo r -p serial_windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do, note that I found this #4894
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilk Am I reading this correctly. That clicking the close box on a child viewport does nothing unless I actually have code that checks for CloseRequested? And that you have to set the vp as not visible in order to destroy it . Thats not at all obvious. (Was trying to work out why the bug reporters app was not closing the child VP after I fixed the bugs I could find)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilk I added to wgpu the equivalent release of the drawing surface, in wgpu not releasing this resulted in the recreate of the vp leaving the original in place (rather than crashing as in glow).
Tested on windows and mac,
Note the wgpu has very strange defferred vp close behavior (also meaning that I did not need to add any close logic to wpgpu_integration). Because there is no close option only the option to no longer request its presence there is some very odd stuff happening. I worried that it was my bad but the current master shows the same thing. After CloseRequest is received you have to stop drawing secondary vp in update, BUT, this means you need another main window draw before the window disappears. I filed a bug on this #4894 . I tried to add the necessary code to the original reports code but could not - I thought it was simply a matter of doing request_repaint but I could not make that work. And the fact that the test_viewports app shows the same bug shows that its not simple.
I think it would be really ice to have an explicit vp.close call (even though that goes again the immediate model VPs are really not transient, the OS knows them (unlike stuff drawn on the gl surfaces). I will investigate and make a separate PR
Also I have not tested on linux becasue I cannot make it build on linux, it complains about a lot of pkg errors.
I will do a separate PR to add vp calls the need window recreation to test_viewports. Done #4907
In summary - I think this PR is complete, apart from not being tested on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
winit::event::WindowEvent::Destroyed => { | ||
log::debug!( | ||
"Received WindowEvent::Destroyed for viewport {:?}", | ||
viewport_id | ||
); | ||
if viewport_id == Some(ViewportId::ROOT) { | ||
return EventResult::Exit; | ||
} else { | ||
return EventResult::Wait; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This make the test excercise the window recreation logic, that resulted in several bugs - see #4862 Adds a check box that turns the close button on and off for child windows
This make the test excercise the window recreation logic, that resulted in several bugs - see emilk#4862 Adds a check box that turns the close button on and off for child windows
* Fixes emilk#3959 There are two bugs racing each other here, which is why it sometimes crashes and sometimes the app just silently exists Bug 1 When the window is recreated a Destroyed event arrives (due to the Drop of the old window). The code that receives this event does not look to see if its the main viewport or a secondary one and unconditionally closes the app. The code path for other platforms is slightly different and does check. I have moved the code that handles the destroy to be in the same place and have the same behavior as the other platforms. Bug 2 At recreate time the window and winit entries of the viewport are set to None (forcin g them to be recreated). But the surface is still bound to the old window, this causes the next context switch to fail. So I simply added a viewport.gl_surface = None too, This is my first egui PR so I hope I have not broken anything. If nothing else I understand a little better how egui works.
This make the test excercise the window recreation logic, that resulted in several bugs - see emilk#4862 Adds a check box that turns the close button on and off for child windows
* Fixes emilk#3959 There are two bugs racing each other here, which is why it sometimes crashes and sometimes the app just silently exists Bug 1 When the window is recreated a Destroyed event arrives (due to the Drop of the old window). The code that receives this event does not look to see if its the main viewport or a secondary one and unconditionally closes the app. The code path for other platforms is slightly different and does check. I have moved the code that handles the destroy to be in the same place and have the same behavior as the other platforms. Bug 2 At recreate time the window and winit entries of the viewport are set to None (forcin g them to be recreated). But the surface is still bound to the old window, this causes the next context switch to fail. So I simply added a viewport.gl_surface = None too, This is my first egui PR so I hope I have not broken anything. If nothing else I understand a little better how egui works.
There are two bugs racing each other here, which is why it sometimes crashes and sometimes the app just silently exists
Bug 1
When the window is recreated a Destroyed event arrives (due to the Drop of the old window). The code that receives this event does not look to see if its the main viewport or a secondary one and unconditionally closes the app. The code path for other platforms is slightly different and does check.
I have moved the code that handles the destroy to be in the same place and have the same behavior as the other platforms.
Bug 2
At recreate time the window and winit entries of the viewport are set to None (forcin g them to be recreated). But the surface is still bound to the old window, this causes the next context switch to fail. So I simply added a viewport.gl_surface = None too,
This is my first egui PR so I hope I have not broken anything. If nothing else I understand a little better how egui works.