From 97b9953247e36b8cbf8d45315ad1a0ab5dfe4516 Mon Sep 17 00:00:00 2001 From: brian cully Date: Sun, 28 Dec 2025 13:11:00 -0500 Subject: use results in render loop where possible --- src/render_loop.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') 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) { - 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) -> Result<(), JsValue> { + web_sys::window().ok_or("no window")?.request_animation_frame(f.as_ref().unchecked_ref())?; + Ok(()) } pub fn new 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(()) } } -- cgit v1.3