From c4fad4456e282feb7ffd643be3ca8c0157071e4b Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 5 Aug 2024 18:41:50 +1000 Subject: [PATCH] tidy(ui): clean up worker tasks when complete --- .../features/controlLayers/konva/CanvasManager.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts index b4236cb043..176455ea03 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts @@ -122,15 +122,15 @@ export class CanvasManager { log: Logger; workerLog: Logger; - _isDebugging: boolean; - isTransforming: PubSub; _store: Store; - _isFirstRender: boolean; _prevState: CanvasV2State; - _worker: Worker; - _tasks: Map void }>; + _isFirstRender: boolean = true; + _isDebugging: boolean = false; + + _worker: Worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module', name: 'worker' }); + _tasks: Map void }> = new Map(); toolState: PubSub; currentFill: PubSub; @@ -149,7 +149,6 @@ export class CanvasManager { this._store = store; this.stateApi = new CanvasStateApi(this._store, this); this._prevState = this.stateApi.getState(); - this._isFirstRender = true; this.log = logger('canvas').child((message) => { return { @@ -188,8 +187,6 @@ export class CanvasManager { this.initialImage = new CanvasInitialImage(this.stateApi.getInitialImageState(), this); this.stage.add(this.initialImage.konva.layer); - this._worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module', name: 'worker' }); - this._tasks = new Map(); this._worker.onmessage = (event: MessageEvent) => { const { type, data } = event.data; if (type === 'log') { @@ -204,6 +201,7 @@ export class CanvasManager { return; } task.onComplete(data.extents); + this._tasks.delete(data.id); } }; this._worker.onerror = (event) => { @@ -212,7 +210,6 @@ export class CanvasManager { this._worker.onmessageerror = () => { this.log.error('Worker message error'); }; - this._isDebugging = false; this.isTransforming = new PubSub(false); this.toolState = new PubSub(this.stateApi.getToolState());