From 08c771fa703f93faf57207a6793cf70cf105de5a Mon Sep 17 00:00:00 2001 From: Andreas Hofstadler Date: Sun, 7 Nov 2021 14:32:18 +0100 Subject: [PATCH 1/3] Allow `Application::run` to return on native platforms --- glutin/src/application.rs | 7 +++++-- src/application.rs | 4 ++-- winit/src/application.rs | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 5d10e96a62..3a96cae924 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -11,6 +11,7 @@ use iced_winit::futures; use iced_winit::futures::channel::mpsc; use iced_winit::{Cache, Clipboard, Debug, Proxy, Settings}; +use crate::glutin::platform::run_return::EventLoopExtRunReturn; use glutin::window::Window; use std::mem::ManuallyDrop; @@ -33,7 +34,7 @@ where let mut debug = Debug::new(); debug.startup_started(); - let event_loop = EventLoop::with_user_event(); + let mut event_loop = EventLoop::with_user_event(); let mut proxy = event_loop.create_proxy(); let mut runtime = { @@ -115,7 +116,7 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - event_loop.run(move |event, _, control_flow| { + event_loop.run_return(move |event, _, control_flow| { use glutin::event_loop::ControlFlow; if let ControlFlow::Exit = control_flow { @@ -148,6 +149,8 @@ where }; } }); + + Ok(()) } async fn run_instance( diff --git a/src/application.rs b/src/application.rs index af04215e35..5728dc0b43 100644 --- a/src/application.rs +++ b/src/application.rs @@ -188,9 +188,9 @@ pub trait Application: Sized { /// Runs the [`Application`]. /// /// On native platforms, this method will take control of the current thread - /// and __will NOT return__ unless there is an [`Error`] during startup. + /// until the event loop of the main window exits. /// - /// It should probably be that last thing you call in your `main` function. + /// Does never return on the web platform /// /// [`Error`]: crate::Error fn run(settings: Settings) -> crate::Result diff --git a/winit/src/application.rs b/winit/src/application.rs index 9ae1364d26..e52283d77e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -17,6 +17,7 @@ use iced_graphics::window; use iced_native::program::Program; use iced_native::{Cache, UserInterface}; +use crate::winit::platform::run_return::EventLoopExtRunReturn; use std::mem::ManuallyDrop; /// An interactive, native cross-platform application. @@ -119,7 +120,7 @@ where let mut debug = Debug::new(); debug.startup_started(); - let event_loop = EventLoop::with_user_event(); + let mut event_loop = EventLoop::with_user_event(); let mut proxy = event_loop.create_proxy(); let mut runtime = { @@ -178,7 +179,7 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - event_loop.run(move |event, _, control_flow| { + event_loop.run_return(move |event, _, control_flow| { use winit::event_loop::ControlFlow; if let ControlFlow::Exit = control_flow { @@ -211,6 +212,8 @@ where }; } }); + + Ok(()) } async fn run_instance( @@ -401,7 +404,7 @@ async fn run_instance( Err(error) => match error { // This is an unrecoverable error. window::SurfaceError::OutOfMemory => { - panic!("{}", error); + panic!("{:?}", error); } _ => { debug.render_finished(); From 0648d9d234346ad0f76757ea25bf06852f5b2002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 29 Nov 2021 14:43:07 +0700 Subject: [PATCH 2/3] Fix imports in `application` modules --- glutin/src/application.rs | 2 +- winit/src/application.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 3a96cae924..a1165de379 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -11,7 +11,6 @@ use iced_winit::futures; use iced_winit::futures::channel::mpsc; use iced_winit::{Cache, Clipboard, Debug, Proxy, Settings}; -use crate::glutin::platform::run_return::EventLoopExtRunReturn; use glutin::window::Window; use std::mem::ManuallyDrop; @@ -29,6 +28,7 @@ where use futures::task; use futures::Future; use glutin::event_loop::EventLoop; + use glutin::platform::run_return::EventLoopExtRunReturn; use glutin::ContextBuilder; let mut debug = Debug::new(); diff --git a/winit/src/application.rs b/winit/src/application.rs index e52283d77e..32423e80c2 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -17,7 +17,6 @@ use iced_graphics::window; use iced_native::program::Program; use iced_native::{Cache, UserInterface}; -use crate::winit::platform::run_return::EventLoopExtRunReturn; use std::mem::ManuallyDrop; /// An interactive, native cross-platform application. @@ -116,6 +115,7 @@ where use futures::task; use futures::Future; use winit::event_loop::EventLoop; + use winit::platform::run_return::EventLoopExtRunReturn; let mut debug = Debug::new(); debug.startup_started(); From 2f50d114612e0dc5cb23389ade2a21819836d254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 29 Nov 2021 14:44:19 +0700 Subject: [PATCH 3/3] Improve documentation of `Application::run` --- src/application.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/application.rs b/src/application.rs index 5728dc0b43..b722c8a338 100644 --- a/src/application.rs +++ b/src/application.rs @@ -188,9 +188,10 @@ pub trait Application: Sized { /// Runs the [`Application`]. /// /// On native platforms, this method will take control of the current thread - /// until the event loop of the main window exits. + /// until the [`Application`] exits. /// - /// Does never return on the web platform + /// On the web platform, this method __will NOT return__ unless there is an + /// [`Error`] during startup. /// /// [`Error`]: crate::Error fn run(settings: Settings) -> crate::Result