mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-30 05:10:03 -04:00
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:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user