Skip to content

Commit

Permalink
Merge pull request #2451 from luzhuang/fix/gltfLoaderThrowError
Browse files Browse the repository at this point in the history
fix: gltfLoader throw error when url load failed
  • Loading branch information
GuoLei1990 authored Dec 6, 2024
2 parents cfe8c34 + 34b705b commit 34e0879
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/loader/src/gltf/parser/GLTFParserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ export class GLTFParserContext {
_addTaskCompletePromise(taskPromise: Promise<any>): void {
const task = this._progress.taskComplete;
task.total += 1;
taskPromise.then(() => {
this._setTaskCompleteProgress(++task.loaded, task.total);
});
taskPromise.then(
() => {
this._setTaskCompleteProgress(++task.loaded, task.total);
},
() => {}
);
}

private _handleSubAsset<T>(
Expand Down
16 changes: 14 additions & 2 deletions tests/src/core/resource/ResourceManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ describe("ResourceManager", () => {
const glTFLoader = ResourceManager._loaders["GLTF"];

const loaderSpy = vi.spyOn(glTFLoader, "load");

engine.resourceManager.load("https://gw.alipayobjects.com/os/bmw-prod/5e3c1e4e-496e-45f8-8e05-f89f2bd5e4a4.glb");
engine.resourceManager.load("https://gw.alipayobjects.com/os/bmw-prod/5e3c1e4e-496e-45f8-8e05-f89f2bd5e4a4.glb");
engine.resourceManager.load("https://gw.alipayobjects.com/os/bmw-prod/5e3c1e4e-496e-45f8-8e05-f89f2bd5e4a4.glb?q=materials[0]");
engine.resourceManager.load(
"https://gw.alipayobjects.com/os/bmw-prod/5e3c1e4e-496e-45f8-8e05-f89f2bd5e4a4.glb?q=materials[0]"
);
expect(loaderSpy).toHaveBeenCalled();
});
});
Expand All @@ -88,4 +90,14 @@ describe("ResourceManager", () => {

// TODO: case for gltf loader load invalid q url, expect to throw
});

describe("load asset", () => {
it("not found", async () => {
try {
await engine.resourceManager.load("/model.glb");
} catch (e) {
expect(e).to.be.an.instanceOf(Error);
}
});
});
});

0 comments on commit 34e0879

Please sign in to comment.