Propagate error from EventLoop creation
Inner panics could make it hard to trouble shoot the issues and for some users ints not desirable. The inner panics were left only when they are used to `assert!` during development.
This commit is contained in:
parent
584aab4cd0
commit
ed26dd58fd
57 changed files with 344 additions and 291 deletions
|
|
@ -75,7 +75,7 @@ use windows_sys::Win32::{
|
|||
|
||||
use crate::{
|
||||
dpi::{PhysicalPosition, PhysicalSize},
|
||||
error::RunLoopError,
|
||||
error::EventLoopError,
|
||||
event::{
|
||||
DeviceEvent, Event, Force, Ime, InnerSizeWriter, RawKeyEvent, Touch, TouchPhase,
|
||||
WindowEvent,
|
||||
|
|
@ -201,7 +201,9 @@ pub struct EventLoopWindowTarget<T: 'static> {
|
|||
}
|
||||
|
||||
impl<T: 'static> EventLoop<T> {
|
||||
pub(crate) fn new(attributes: &mut PlatformSpecificEventLoopAttributes) -> Self {
|
||||
pub(crate) fn new(
|
||||
attributes: &mut PlatformSpecificEventLoopAttributes,
|
||||
) -> Result<Self, EventLoopError> {
|
||||
let thread_id = unsafe { GetCurrentThreadId() };
|
||||
|
||||
if !attributes.any_thread && thread_id != main_thread_id() {
|
||||
|
|
@ -228,7 +230,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
Default::default(),
|
||||
);
|
||||
|
||||
EventLoop {
|
||||
Ok(EventLoop {
|
||||
thread_msg_sender,
|
||||
window_target: RootELW {
|
||||
p: EventLoopWindowTarget {
|
||||
|
|
@ -239,28 +241,28 @@ impl<T: 'static> EventLoop<T> {
|
|||
_marker: PhantomData,
|
||||
},
|
||||
msg_hook: attributes.msg_hook.take(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn window_target(&self) -> &RootELW<T> {
|
||||
&self.window_target
|
||||
}
|
||||
|
||||
pub fn run<F>(mut self, event_handler: F) -> Result<(), RunLoopError>
|
||||
pub fn run<F>(mut self, event_handler: F) -> Result<(), EventLoopError>
|
||||
where
|
||||
F: FnMut(Event<T>, &RootELW<T>, &mut ControlFlow),
|
||||
{
|
||||
self.run_ondemand(event_handler)
|
||||
}
|
||||
|
||||
pub fn run_ondemand<F>(&mut self, mut event_handler: F) -> Result<(), RunLoopError>
|
||||
pub fn run_ondemand<F>(&mut self, mut event_handler: F) -> Result<(), EventLoopError>
|
||||
where
|
||||
F: FnMut(Event<T>, &RootELW<T>, &mut ControlFlow),
|
||||
{
|
||||
{
|
||||
let runner = &self.window_target.p.runner_shared;
|
||||
if runner.state() != RunnerState::Uninitialized {
|
||||
return Err(RunLoopError::AlreadyRunning);
|
||||
return Err(EventLoopError::AlreadyRunning);
|
||||
}
|
||||
|
||||
let event_loop_windows_ref = &self.window_target;
|
||||
|
|
@ -295,7 +297,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
if exit_code == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(RunLoopError::ExitFailure(exit_code))
|
||||
Err(EventLoopError::ExitFailure(exit_code))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue