summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-03-13 21:02:02 -0400
committerLLLL Colonq <llll@colonq>2025-03-13 21:02:02 -0400
commitefd38f455965e71233a6a6df4e803736fd1190fd (patch)
tree46ce293f5a1c9d6553d9db7ab158ec435ec1381a
parent2a7b0690f4dbc33c9fc2b0b1eeb814b44eb20c30 (diff)
Fix WASM errors
-rw-r--r--src/lib.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9bbc60d..1d7d061 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -41,14 +41,14 @@ static mut CTX: Option<*const context::Context> = None;
static mut ST: Option<*mut state::State> = None;
static mut G: Option<*mut std::ffi::c_void> = None;
-pub fn contextualize<F, G>(mut f: F)
+pub fn contextualize<F, G, X>(mut f: F) -> X
where
G: state::Game + 'static,
- F: FnMut(&context::Context, &mut state::State, &mut G) {
+ F: FnMut(&context::Context, &mut state::State, &mut G) -> X {
unsafe {
match (CTX, ST, G) {
(Some(c), Some(s), Some(g)) => f(&*c, &mut*s, &mut*(g as *mut G)),
- _ => log::info!("context not set"),
+ _ => panic!("context not set"),
}
}
}
@@ -181,7 +181,7 @@ where
}
#[cfg(target_arch = "wasm32")]
-pub async fn run<'a, F, G, Fut>(w: u32, h: u32, options: Options, gnew: F) -> Erm<()>
+pub async fn run<'a, F, G, Fut>(w: u32, h: u32, options: Options, gnew: F)
where
Fut: std::future::Future<Output = G>,
G: state::Game + 'static,
@@ -230,9 +230,11 @@ where
G = Some(game as *mut G as *mut std::ffi::c_void);
}
+ let res = std::rc::Rc::new(std::cell::RefCell::new(Ok(())));
+ let result = res.clone();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Wait);
- event_loop.spawn(|event, elwt| {
- contextualize(|ctx, st, game: &mut G| {
+ event_loop.spawn(move |event, elwt| {
+ let res: Erm<()> = contextualize(|ctx, st, game: &mut G| {
match &event {
winit::event::Event::WindowEvent {
event: wev,
@@ -308,7 +310,14 @@ where
_ => {},
}
+ Ok(())
});
+ if let Err(e) = res {
+ *result.borrow_mut() = Err(e);
+ elwt.exit();
+ }
});
- Ok(())
+ if let Err(e) = res.replace(Ok(())) {
+ panic!("{}", e);
+ }
}