Skip to content
Snippets Groups Projects
Commit ed97f664 authored by Grant's avatar Grant
Browse files

be more aggressive with loading canvas renderer

parent 0282576f
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ export class Canvas extends EventEmitter<CanvasEvents> { ...@@ -36,7 +36,7 @@ export class Canvas extends EventEmitter<CanvasEvents> {
lastPlace: number | undefined; lastPlace: number | undefined;
private bypassCooldown = false; private bypassCooldown = false;
private _delayedLoad: ReturnType<typeof setTimeout>; // private _delayedLoad: ReturnType<typeof setTimeout>;
constructor(canvas: HTMLCanvasElement, PanZoom: PanZoom) { constructor(canvas: HTMLCanvasElement, PanZoom: PanZoom) {
super(); super();
...@@ -47,7 +47,7 @@ export class Canvas extends EventEmitter<CanvasEvents> { ...@@ -47,7 +47,7 @@ export class Canvas extends EventEmitter<CanvasEvents> {
this.canvas = canvas; this.canvas = canvas;
this.PanZoom = PanZoom; this.PanZoom = PanZoom;
this._delayedLoad = setTimeout(() => this.delayedLoad(), 1000); this.loadRenderer();
this.PanZoom.addListener("hover", this.handleMouseMove.bind(this)); this.PanZoom.addListener("hover", this.handleMouseMove.bind(this));
this.PanZoom.addListener("click", this.handleMouseDown.bind(this)); this.PanZoom.addListener("click", this.handleMouseDown.bind(this));
...@@ -63,7 +63,6 @@ export class Canvas extends EventEmitter<CanvasEvents> { ...@@ -63,7 +63,6 @@ export class Canvas extends EventEmitter<CanvasEvents> {
destroy() { destroy() {
getRenderer().stopRender(); getRenderer().stopRender();
getRenderer().off("ready"); getRenderer().off("ready");
if (this._delayedLoad) clearTimeout(this._delayedLoad);
this.PanZoom.removeListener("hover", this.handleMouseMove.bind(this)); this.PanZoom.removeListener("hover", this.handleMouseMove.bind(this));
this.PanZoom.removeListener("click", this.handleMouseDown.bind(this)); this.PanZoom.removeListener("click", this.handleMouseDown.bind(this));
...@@ -75,9 +74,18 @@ export class Canvas extends EventEmitter<CanvasEvents> { ...@@ -75,9 +74,18 @@ export class Canvas extends EventEmitter<CanvasEvents> {
/** /**
* React.Strict remounts the main component, causing a quick remount, which then causes errors related to webworkers * React.Strict remounts the main component, causing a quick remount, which then causes errors related to webworkers
*
* If #useCanvas fails, it's most likely due to that
*/ */
delayedLoad() { loadRenderer() {
getRenderer().useCanvas(this.canvas, "main"); try {
getRenderer().useCanvas(this.canvas, "main");
} catch (e) {
console.warn(
"[Canvas#loadRenderer] Failed at #useCanvas, this shouldn't be fatal",
e
);
}
} }
setSize(width: number, height: number) { setSize(width: number, height: number) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment