diff options
Diffstat (limited to 'src/render_loop.rs')
| -rw-r--r-- | src/render_loop.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/render_loop.rs b/src/render_loop.rs index 9b8d8f5..5a5e21a 100644 --- a/src/render_loop.rs +++ b/src/render_loop.rs @@ -1,6 +1,7 @@ use std::cell::RefCell; use std::rc::Rc; +use log::error; use wasm_bindgen::prelude::*; pub struct RenderLoop { @@ -8,11 +9,9 @@ pub struct RenderLoop { } impl RenderLoop { - fn request_animation_frame(f: &Closure<dyn FnMut(f64)>) { - web_sys::window() - .expect("no window") - .request_animation_frame(f.as_ref().unchecked_ref()) - .expect("should register `requestAnimationFrame` OK"); + fn request_animation_frame(f: &Closure<dyn FnMut(f64)>) -> Result<(), JsValue> { + web_sys::window().ok_or("no window")?.request_animation_frame(f.as_ref().unchecked_ref())?; + Ok(()) } pub fn new<T: FnMut(f64) -> bool + 'static>(mut fun: T) -> Self { @@ -21,14 +20,16 @@ impl RenderLoop { *inner.borrow_mut() = Closure::new(move |t| { if fun(t) { - Self::request_animation_frame(&rloop.borrow()); + if let Err(e) = Self::request_animation_frame(&rloop.borrow()) { + error!("couldn't request animation frame: {:?}", e); + } } }); Self { inner } } pub fn start(&self) -> Result<(), JsValue> { - Self::request_animation_frame(&self.inner.borrow()); + Self::request_animation_frame(&self.inner.borrow())?; Ok(()) } } |
