mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Return errors from run_and_exit
This commit is contained in:
@@ -224,14 +224,18 @@ fn run_and_return(
|
||||
returned_result
|
||||
}
|
||||
|
||||
fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp + 'static) -> ! {
|
||||
fn run_and_exit(
|
||||
event_loop: EventLoop<UserEvent>,
|
||||
mut winit_app: impl WinitApp + 'static,
|
||||
) -> Result<()> {
|
||||
use winit::event_loop::ControlFlow;
|
||||
log::debug!("Entering the winit event loop (run)…");
|
||||
|
||||
// When to repaint what window
|
||||
let mut windows_next_repaint_times = HashMap::default();
|
||||
|
||||
let result = event_loop.run(move |event, event_loop_window_target| {
|
||||
event_loop
|
||||
.run(move |event, event_loop_window_target| {
|
||||
crate::profile_scope!("winit_event", short_event_description(&event));
|
||||
|
||||
let event_result = match &event {
|
||||
@@ -255,7 +259,8 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
|
||||
}) => {
|
||||
let current_frame_nr = winit_app.frame_nr(*viewport_id);
|
||||
if current_frame_nr == *frame_nr || current_frame_nr == *frame_nr + 1 {
|
||||
if let Some(window_id) = winit_app.window_id_from_viewport_id(*viewport_id) {
|
||||
if let Some(window_id) = winit_app.window_id_from_viewport_id(*viewport_id)
|
||||
{
|
||||
EventResult::RepaintAt(window_id, *when)
|
||||
} else {
|
||||
EventResult::Wait
|
||||
@@ -362,16 +367,11 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
|
||||
.map(|window| window.request_redraw())
|
||||
});
|
||||
|
||||
event_loop_window_target.set_control_flow(ControlFlow::WaitUntil(next_repaint_time));
|
||||
event_loop_window_target
|
||||
.set_control_flow(ControlFlow::WaitUntil(next_repaint_time));
|
||||
};
|
||||
});
|
||||
|
||||
std::process::exit(if let Err(e) = result {
|
||||
log::warn!("Error from event loop: {e}");
|
||||
1
|
||||
} else {
|
||||
0
|
||||
});
|
||||
})
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -394,7 +394,7 @@ pub fn run_glow(
|
||||
|
||||
let event_loop = create_event_loop(&mut native_options);
|
||||
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
||||
run_and_exit(event_loop, glow_eframe);
|
||||
run_and_exit(event_loop, glow_eframe)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -417,5 +417,5 @@ pub fn run_wgpu(
|
||||
|
||||
let event_loop = create_event_loop(&mut native_options);
|
||||
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
|
||||
run_and_exit(event_loop, wgpu_eframe);
|
||||
run_and_exit(event_loop, wgpu_eframe)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user