From: Ian Jackson Date: Sat, 16 Apr 2022 11:27:14 +0000 (+0100) Subject: dice js: Make s.anim_id be possibly null X-Git-Tag: otter-1.1.0~532 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=03310afb4168c8db7261b2dda7b81edea9154c12;p=otter.git 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 --- 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;