Skip to content

Commit

Permalink
move abort scene resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
SigveBergslien committed Jan 10, 2025
1 parent d2158b4 commit 0f2e793
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions core3d/modules/octree/loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AbortAllMessage, AbortMessage, InitMessage, CloseMessage, LoadMessage, MessageRequest, MessageResponse, NodePayload, ParseMessage, ParseConfig } from "./worker";
import { OctreeNode } from "./node.js";
import type { DeviceProfile } from "core3d/device.js";
import type { RenderContext } from "core3d/context";

interface PayloadPromiseMethods { readonly resolve: (value: NodePayload | undefined) => void, readonly reject: (reason: string) => void };

Expand All @@ -13,7 +14,7 @@ export class NodeLoader {
private resolveBuffer: (() => void) | undefined;
aborted = false;

constructor(readonly worker: Worker) {
constructor(readonly worker: Worker, readonly renderContext: RenderContext) {
worker.onmessage = e => {
this.receive(e.data as MessageResponse);
}
Expand Down Expand Up @@ -47,6 +48,7 @@ export class NodeLoader {
const { resolveAbortAll } = this;
this.resolveAbortAll = undefined;
resolveAbortAll?.();
this.renderContext.setSceneResolved(true);
return;
}
const { id } = msg;
Expand All @@ -60,9 +62,11 @@ export class NodeLoader {
resolve(msg);
break;
case "aborted":
this.renderContext.setSceneResolved(this.payloadPromises.size == 0);
resolve(undefined);
break;
case "error":
this.renderContext.setSceneResolved(this.payloadPromises.size == 0);
reject(msg.error);
break;
}
Expand Down Expand Up @@ -110,10 +114,7 @@ export class NodeLoader {
const loadMsg: LoadMessage = { kind: "load", id, config, url: url.toString(), byteSize, enableOutlines, applyFilter };
console.assert(byteSize != 0);
const abortMsg: AbortMessage = { kind: "abort", id };
const abort = () => {
node.context.renderContext.setSceneResolved(this.payloadPromises.size == 1);
this.send(abortMsg);
}
const abort = () => { this.send(abortMsg); }
node.download = { abort };
this.send(loadMsg);
return new Promise<NodePayload | undefined>((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion core3d/modules/octree/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class OctreeModule implements RenderModule {
const uniforms = this.createUniforms();
const resources = await this.createResources(context, uniforms);

const loader = new NodeLoader(context.imports.loaderWorker);
const loader = new NodeLoader(context.imports.loaderWorker, context);
const maxObjects = 25_000_000;// TODO: Get from device profile?
const maxByteLength = maxObjects + 4; // add four bytes for mutex
const buffer = new SharedArrayBuffer(maxByteLength);
Expand Down

0 comments on commit 0f2e793

Please sign in to comment.