Skip to content

Commit

Permalink
Fix problem with Parcel reload
Browse files Browse the repository at this point in the history
Parcel uses "hot module replacement" (HMR), which has quite intuitive
problems with `requestAnimationFrame`-based animation:
parcel-bundler/parcel#289

We now use a pretty ridiculous hack to cancel previous animation loops
when setting up new ones for our examples.
  • Loading branch information
sampsyo committed Jul 24, 2018
1 parent 02f7736 commit 424013e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/lglexample.ts
Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down

0 comments on commit 424013e

Please sign in to comment.