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
|
|
@ -12,7 +12,7 @@ use orbclient::{
|
|||
use raw_window_handle::{OrbitalDisplayHandle, RawDisplayHandle};
|
||||
|
||||
use crate::{
|
||||
error::RunLoopError,
|
||||
error::EventLoopError,
|
||||
event::{self, Ime, Modifiers, StartCause},
|
||||
event_loop::{self, ControlFlow},
|
||||
keyboard::{
|
||||
|
|
@ -22,8 +22,8 @@ use crate::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
DeviceId, KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket,
|
||||
TimeSocket, WindowId, WindowProperties,
|
||||
DeviceId, KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes,
|
||||
RedoxSocket, TimeSocket, WindowId, WindowProperties,
|
||||
};
|
||||
|
||||
fn convert_scancode(scancode: u8) -> KeyCode {
|
||||
|
|
@ -270,12 +270,20 @@ pub struct EventLoop<T: 'static> {
|
|||
}
|
||||
|
||||
impl<T: 'static> EventLoop<T> {
|
||||
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> Self {
|
||||
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> Result<Self, EventLoopError> {
|
||||
let (user_events_sender, user_events_receiver) = mpsc::channel();
|
||||
|
||||
let event_socket = Arc::new(RedoxSocket::event().unwrap());
|
||||
let event_socket = Arc::new(
|
||||
RedoxSocket::event()
|
||||
.map_err(OsError::new)
|
||||
.map_err(|error| EventLoopError::Os(os_error!(error)))?,
|
||||
);
|
||||
|
||||
let wake_socket = Arc::new(TimeSocket::open().unwrap());
|
||||
let wake_socket = Arc::new(
|
||||
TimeSocket::open()
|
||||
.map_err(OsError::new)
|
||||
.map_err(|error| EventLoopError::Os(os_error!(error)))?,
|
||||
);
|
||||
|
||||
event_socket
|
||||
.write(&syscall::Event {
|
||||
|
|
@ -283,9 +291,10 @@ impl<T: 'static> EventLoop<T> {
|
|||
flags: syscall::EventFlags::EVENT_READ,
|
||||
data: wake_socket.0.fd,
|
||||
})
|
||||
.unwrap();
|
||||
.map_err(OsError::new)
|
||||
.map_err(|error| EventLoopError::Os(os_error!(error)))?;
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
windows: Vec::new(),
|
||||
window_target: event_loop::EventLoopWindowTarget {
|
||||
p: EventLoopWindowTarget {
|
||||
|
|
@ -299,7 +308,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
},
|
||||
_marker: std::marker::PhantomData,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn process_event<F>(
|
||||
|
|
@ -443,7 +452,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run<F>(mut self, mut event_handler_inner: F) -> Result<(), RunLoopError>
|
||||
pub fn run<F>(mut self, mut event_handler_inner: F) -> Result<(), EventLoopError>
|
||||
where
|
||||
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
|
|
@ -685,7 +694,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
if code == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(RunLoopError::ExitFailure(code))
|
||||
Err(EventLoopError::ExitFailure(code))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#![cfg(target_os = "redox")]
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
||||
|
||||
|
|
@ -176,13 +178,18 @@ impl<'a> fmt::Display for WindowProperties<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct OsError;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OsError(Arc<syscall::Error>);
|
||||
|
||||
impl OsError {
|
||||
fn new(error: syscall::Error) -> Self {
|
||||
Self(Arc::new(error))
|
||||
}
|
||||
}
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
impl Display for OsError {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(fmt, "Redox OS Error")
|
||||
self.0.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue