Skip to content

Commit

Permalink
fix(v2): error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
aamir1995 committed Sep 1, 2023
1 parent 5aa0e30 commit 4540bf6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 55 deletions.
105 changes: 51 additions & 54 deletions v2/demo-snippets/hosts/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,55 @@ import { RenderStateChanges, View } from "@novorender/api";
import { vec3 } from "gl-matrix";

export abstract class BaseDemoHost {
readonly view: View;
readonly center = vec3.create();
abortController: AbortController | undefined;

constructor(readonly context: IDemoContext) {
const {
canvasElements: { primaryCanvas: canvas },
deviceProfile,
imports,
} = this.context;
this.view = new View(canvas, deviceProfile, imports);
}

async run() {
const { view } = this;
this.abortController = new AbortController();
await this.init?.();
view.animate = (time) => {
try {
this.animate?.(time);
} catch (error) {
console.log(error);
this.context.reportErrors(error);
}
};

await view.run(this.abortController.signal);
view.dispose();
}

init?(): Promise<void>;
animate?(time: number): Promise<void>;

async loadScene(url: string) {
const { view } = this;
const config = await view.loadSceneFromURL(new URL(url));
const { center, radius } = config.boundingSphere;
view.activeController.autoFit(center, radius);
const [cx, cy, cz] = config.center;
vec3.set(this.center, cx, -cz, cy);
}

async modifyRenderState(stateChanges: RenderStateChanges) {
const errors = this.view.validateRenderState(stateChanges);
if (errors.length == 0) {
this.view.modifyRenderState(stateChanges);
} else {
this.context.reportErrors(errors);
}
}

exit() {
this.abortController?.abort();
}
readonly view: View;
readonly center = vec3.create();
abortController: AbortController | undefined;

constructor(readonly context: IDemoContext) {
const {
canvasElements: { primaryCanvas: canvas },
deviceProfile,
imports,
} = this.context;
this.view = new View(canvas, deviceProfile, imports);
}

async run() {
const { view } = this;
this.abortController = new AbortController();
await this.init?.();
view.animate = (time) => {
try {
this.animate?.(time);
} catch (error) {
console.log(error);
this.context.reportErrors(error);
}
};

await view.run(this.abortController.signal);
view.dispose();
}

init?(): Promise<void>;
animate?(time: number): Promise<void>;

async loadScene(url: string) {
const { view } = this;
const config = await view.loadSceneFromURL(new URL(url));
const { center, radius } = config.boundingSphere;
view.activeController.autoFit(center, radius);
const [cx, cy, cz] = config.center;
vec3.set(this.center, cx, -cz, cy);
}

async modifyRenderState(stateChanges: RenderStateChanges) {
const errors = this.view.validateRenderState(stateChanges);
this.view.modifyRenderState(stateChanges);
this.context.reportErrors(errors);
}

exit() {
this.abortController?.abort();
}
}
2 changes: 1 addition & 1 deletion v2/src/components/MonacoWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default function MonacoWrapper({ code, demoName, dirName, fileName, descr
}
}, [monaco]);

const reportErrors = (...errors: any[]) => {
const reportErrors = (errors: any[]) => {
setModuleInternalValidationErrors([...((errors || []) as Error[])]);
if (errors && errors.length) {
// console.log("validation errors ==> ", errors);
Expand Down

0 comments on commit 4540bf6

Please sign in to comment.