From 03310afb4168c8db7261b2dda7b81edea9154c12 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Apr 2022 12:27:14 +0100 Subject: [PATCH] dice js: Make s.anim_id be possibly null We might not have requested an animation frame. If so we shouldn't cancel it. Nor, if we have already cancelled it, or if it has occurred. Signed-off-by: Ian Jackson --- templates/script.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/script.ts b/templates/script.ts index 5268aac1..464387e0 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -2263,7 +2263,7 @@ function startup() { } type DieSpecialRendering = SpecialRendering & { - anim_id: number, + anim_id: number | null, }; special_renderings['Die'] = function(piece: PieceId, p: PieceInfo, s: DieSpecialRendering) { @@ -2274,11 +2274,15 @@ special_renderings['Die'] = function(piece: PieceId, p: PieceInfo, } as any; function die_render_frame(piece: PieceId, p: PieceInfo, s: DieSpecialRendering, ts: DOMHighResTimeStamp) { + s.anim_id = null; console.log('DIE RENDER', piece, ts); } function die_rendering_stop(piece: PieceId, p: PieceInfo, s: DieSpecialRendering) { - window.cancelAnimationFrame(s.anim_id); + let anim_id = s.anim_id; + if (anim_id == null) return; + s.anim_id = null; + window.cancelAnimationFrame(anim_id); } declare var wasm_input : any; -- 2.30.2