Skip to content

Commit

Permalink
fix: cancelAnimationFrame after canvas destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Oct 16, 2024
1 parent 56c0b68 commit 28fc1a6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/g-lite/src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export class Canvas extends EventTarget implements ICanvas {
* rAF in auto rendering
*/
private frameId?: number;

private inited = false;
private destroyed = false;
private readyPromise: Promise<any> | undefined;
private resolveReadyPromise: () => void;

Expand Down Expand Up @@ -422,6 +422,8 @@ export class Canvas extends EventTarget implements ICanvas {
this.context.renderingContext.root = null;
}

this.destroyed = true;

if (!skipTriggerEvent) {
this.dispatchEvent(new CustomEvent(CanvasEvent.AFTER_DESTROY));
}
Expand Down Expand Up @@ -515,6 +517,7 @@ export class Canvas extends EventTarget implements ICanvas {

private run() {
const tick = (time: number, frame?: XRFrame) => {
if (this.destroyed) return this.cancelAnimationFrame(this.frameId);
this.render(frame);
this.frameId = this.requestAnimationFrame(tick);
};
Expand Down

0 comments on commit 28fc1a6

Please sign in to comment.