Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
- Throw during next call to update
- use catch instead of onRejected
- Don't update CHANGES.md for minor bug
  • Loading branch information
angrycat9000 committed Nov 14, 2024
1 parent f2a7bb9 commit 79133ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
8 changes: 0 additions & 8 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Change Log

### 1.124.0

#### @cesium/engine

##### Fixes :wrench:

- Handle uncaught promise rejection in `Skybox.update` that could cause tests to fail[#12307](https://github.com/CesiumGS/cesium/pull/12307)

### 1.123.1 - 2024-11-07

#### @cesium/engine
Expand Down
28 changes: 21 additions & 7 deletions packages/engine/Source/Scene/SkyBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function SkyBox(options) {

this._attributeLocations = undefined;
this._useHdr = undefined;
this._hasError = false;
this._error = false;
}

/**
Expand Down Expand Up @@ -111,6 +113,15 @@ SkyBox.prototype.update = function (frameState, useHdr) {
return undefined;
}

// Throw any errors that had previously occurred asynchronously so they aren't
// ignored when running. See https://github.com/CesiumGS/cesium/pull/12307
if (this._hasError) {
const error = this._error;
this._hasError = false;
this._error = undefined;
throw error;
}

if (this._sources !== this.sources) {
this._sources = this.sources;
const sources = this.sources;
Expand Down Expand Up @@ -141,15 +152,18 @@ SkyBox.prototype.update = function (frameState, useHdr) {

if (typeof sources.positiveX === "string") {
// Given urls for cube-map images. Load them.
loadCubeMap(context, this._sources).then(
function (cubeMap) {
loadCubeMap(context, this._sources)
.then(function (cubeMap) {
that._cubeMap = that._cubeMap && that._cubeMap.destroy();
that._cubeMap = cubeMap;
},
function (error) {
console.error("Skybox cube map failed to load", error);
},
);
})
.catch((error) => {
// Defer throwing the error until the next call to update to prevent
// test from failing in `afterAll` if this is rejected after the test
// using the Skybox ends. See https://github.com/CesiumGS/cesium/pull/12307
this._hasError = true;
this._error = error;
});
} else {
this._cubeMap = this._cubeMap && this._cubeMap.destroy();
this._cubeMap = new CubeMap({
Expand Down
16 changes: 9 additions & 7 deletions packages/engine/Specs/Scene/SkyBoxSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,9 @@ describe(
}).toThrowDeveloperError();
});

it("handles error when Resources fail to load", async () => {
spyOn(Resource.prototype, "fetchImage").and.rejectWith(
"intentional error for test",
);
it("defers throwing error when Resources fail to load until next call to update", async () => {
const error = new Error("intentional error for test");
spyOn(Resource.prototype, "fetchImage").and.rejectWith(error);

skyBox = new SkyBox({
sources: {
Expand All @@ -376,9 +375,12 @@ describe(
scene.skyBox = skyBox;
skyBox.update(scene.frameState);

// Flush macro task queue to allow the rejections to be throw in this
// function, otherwise the error ends up happening in `afterAll`
await new Promise((resolve) => window.setTimeout(resolve, 1));
// Flush macro task queue to allow the rejections to be thrown
await new Promise((resolve) => window.setTimeout(resolve, 0));

expect(skyBox._hasError).toBeTrue();
expect(skyBox._error).toEqual(error);
expect(() => skyBox.update(scene.frameState)).toThrow(error);
});
},
"WebGL",
Expand Down

0 comments on commit 79133ea

Please sign in to comment.