From 424013e315d09f3f0d70ecba09e8f49b5c66b4de Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 24 Jul 2018 16:53:13 -0400 Subject: [PATCH] Fix problem with Parcel reload Parcel uses "hot module replacement" (HMR), which has quite intuitive problems with `requestAnimationFrame`-based animation: https://github.com/parcel-bundler/parcel/issues/289 We now use a pretty ridiculous hack to cancel previous animation loops when setting up new ones for our examples. --- examples/lglexample.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/lglexample.ts b/examples/lglexample.ts index d48c15c..ef50aa8 100644 --- a/examples/lglexample.ts +++ b/examples/lglexample.ts @@ -294,7 +294,7 @@ export function setup(canvas: HTMLCanvasElement, render: (view: mat4, projection gl.clear(gl.COLOR_BUFFER_BIT); // Set up the render loop. - registerAnimator(() => { + let cancel = registerAnimator(() => { // Update the camera view. camera.view(view); camera.tick(); @@ -314,6 +314,13 @@ export function setup(canvas: HTMLCanvasElement, render: (view: mat4, projection render(view, projection); }); + // A **total hack** to cancel previously-registered animation loops. + let w = window as any; + if (w._linguineCancel) { + w._linguineCancel(); + } + w._linguineCancel = cancel; + return gl; }