aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbrian cully <bjc@spork.org>2025-12-28 13:11:00 -0500
committerbrian cully <bjc@spork.org>2025-12-28 13:11:00 -0500
commit97b9953247e36b8cbf8d45315ad1a0ab5dfe4516 (patch)
treea0e399a1224724a0fd92815dafe511a928d8de00 /src
parentad1a3b5364f51772ff303f8b4f36ee4a0157191d (diff)
downloadpolyring-97b9953247e36b8cbf8d45315ad1a0ab5dfe4516.tar.gz
polyring-97b9953247e36b8cbf8d45315ad1a0ab5dfe4516.zip
use results in render loop where possible
Diffstat (limited to 'src')
-rw-r--r--src/render_loop.rs15
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(())
}
}