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

Support exiting event loop (closing native window) without quitting program #1223

Closed
surban opened this issue Feb 7, 2022 · 9 comments · Fixed by #1889
Closed

Support exiting event loop (closing native window) without quitting program #1223

surban opened this issue Feb 7, 2022 · 9 comments · Fixed by #1889
Labels
eframe Relates to epi and eframe egui-winit porblems related to winit feature New feature or request

Comments

@surban
Copy link
Contributor

surban commented Feb 7, 2022

Is your feature request related to a problem? Please describe.
I am using egui in a command line application. The app displays a window for the user to provide some input. After the window is closed egui should exit the event loop and return from eframe::run_native, so that the app can continue running.

However this is currently impossible because the return type of eframe::run_native is ! and std::process::exit is called when the window is closed.

Describe the solution you'd like
Change eframe::run_native to return to the caller once all windows have been closed and the event loop is done.

Optionally provide a way to return a value to the caller via epi::frame::quit. A Box<dyn Any> would suffice.

Describe alternatives you've considered
Since the event loop must be run on the main thread and std::process::exit is called, I see no alternative.

@surban surban added the feature New feature or request label Feb 7, 2022
@emilk emilk added eframe Relates to epi and eframe egui-winit porblems related to winit labels Feb 7, 2022
@emilk
Copy link
Owner

emilk commented Feb 7, 2022

Related issue: #427

This is a limitation from winit, so I suggest you open a winit issue on this: https://docs.rs/winit/latest/winit/event_loop/struct.EventLoop.html#method.run

You can use another backend (e.g. egui-macroquad) if this is blocking you.

@surban
Copy link
Contributor Author

surban commented Feb 8, 2022

This is a limitation from winit, so I suggest you open a winit issue on this: https://docs.rs/winit/latest/winit/event_loop/struct.EventLoop.html#method.run

According to winit developers this is already supported, see rust-windowing/winit#2187 (comment) .

@emilk
Copy link
Owner

emilk commented Feb 9, 2022

I've tried run_return in the past, and it caused two problems:

So I reverted it in 3e1db88

@emilk emilk closed this as completed Feb 9, 2022
@emilk emilk changed the title Support exiting event loop without quitting program Support exiting event loop (closing native window) without quitting program Mar 22, 2022
@emilk emilk reopened this Mar 22, 2022
@emilk
Copy link
Owner

emilk commented Mar 22, 2022

Reopened, because this is something a lot of people want. We need to either change how winit::EventLoop::run works, or fix the problems with winit::EventLoop::run_return, or test an alternative, like tao

@d10sfan
Copy link
Contributor

d10sfan commented May 7, 2022

Are there any workarounds for this? Was attempting to use egui_glow but I'm unable to remove the window without quitting the entire application. Trying to get out of the loop just causes a frozen window to stay there until the application is closed.

@emilk
Copy link
Owner

emilk commented Aug 3, 2022

This will finally be fixed in #1889 🥳

@d10sfan
Copy link
Contributor

d10sfan commented Aug 4, 2022

@emilk Great! Will this apply to egui_glow/glutin as well?

@emilk
Copy link
Owner

emilk commented Aug 4, 2022

There is nothing stopping you from using run_return with egui_glow 0.18 - just follow the structure in my PR!

The PR is for eframe, and if it works well I will update the "pure" egui_glow example to also use the run_return method.

@d10sfan
Copy link
Contributor

d10sfan commented Aug 5, 2022

In my case when trying this, the glutin window stays around after getting out of the run_return, similar to this issue (not my repo): rust-windowing/winit#2467

This is with trying egui 0.18 on Linux. Something else I noticed was that if I create two windows back to back (meaning create a window, close it, then open another one, all in the same process), the second window gets the final events, like LoopDestroyed, causing the second window to immediately close.

It's possible I'm not doing something correct in my own code (https://github.com/luxtorpeda-dev/luxtorpeda/blob/a9cafca4ab96bcedd318ecd9fec583daa3a4af81/src/ui.rs#L170) in the loop, so I'm curious what the example looks like as well for comparison. Once the example is there, I'll re-test that and then see if I can create a re-producible demo with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe egui-winit porblems related to winit feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants