Skip to content

Commit

Permalink
Merge branch 'main' into update-gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed May 14, 2024
2 parents a2907eb + e4a93bb commit b94ffb7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

### 1.118

#### @cesium/engine

##### Fixes :wrench:

- Fixed a bug where `TaskProcessor` worker loading would check the worker module ID rather than the absolute URL when determining if it is cross-origin. [#11833](https://github.com/CesiumGS/cesium/pull/11833)
- Fixed a bug where cross-origin workers would error when loaded with the CommonJS `importScripts` shim instead of an ESM `import`. [#11833](https://github.com/CesiumGS/cesium/pull/11833)

### 1.117

#### @cesium/engine
Expand All @@ -13,6 +22,7 @@

- Fixed a bug where a data source was not automatically rendered after is was added in request render mode. [#11934](https://github.com/CesiumGS/cesium/pull/11934)
- Fixes Typescript definition for `Event.raiseEvent`. [#10498](https://github.com/CesiumGS/cesium/issues/10498)
- Fixed a bug that Label position height may not be correctly updated when its HeightReference is relative. [#11929](https://github.com/CesiumGS/cesium/pull/11929)

#### @cesium/widgets

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Andrew McDowell](https://github.com/madole)
- [Tony Luk](https://github.com/impactblue573)
- [Daniel Cooper](https://github.com/moodragon46)
- [Harry Morris](https://github.com/harrythemorris)
- [GeoFS](https://www.geo-fs.com)
- [Xavier Tassin](https://github.com/xtassin/)
- [Esri](https://www.esri.com)
Expand Down
22 changes: 19 additions & 3 deletions packages/engine/Source/Core/TaskProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,34 @@ function urlFromScript(script) {
function createWorker(url) {
const uri = new Uri(url);
const isUri = uri.scheme().length !== 0 && uri.fragment().length === 0;
const moduleID = url.replace(/\.js$/, "");

const options = {};
let workerPath;
let crossOriginUrl;

// If we are provided a fully resolved URL, check it is cross-origin
// Or if provided a module ID, check the full absolute URL instead.
if (isCrossOriginUrl(url)) {
crossOriginUrl = url;
} else if (!isUri) {
const moduleAbsoluteUrl = buildModuleUrl(
`${TaskProcessor._workerModulePrefix}/${moduleID}.js`
);

if (isCrossOriginUrl(moduleAbsoluteUrl)) {
crossOriginUrl = moduleAbsoluteUrl;
}
}

if (crossOriginUrl) {
// To load cross-origin, create a shim worker from a blob URL
const script = `importScripts("${url}");`;
const script = `import "${crossOriginUrl}";`;
workerPath = urlFromScript(script);
options.type = "module";
return new Worker(workerPath, options);
}

const moduleID = url.replace(/\.js$/, "");

/* global CESIUM_WORKERS */
if (!isUri && typeof CESIUM_WORKERS !== "undefined") {
// If the workers are embedded, create a shim worker from the embedded script data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import ShaderDestination from "../../Renderer/ShaderDestination.js";
import VerticalExaggerationStageVS from "../../Shaders/Model/VerticalExaggerationStageVS.js";

/**
* The custom shader pipeline stage takes GLSL callbacks from the
* {@link CustomShader} and inserts them into the overall shader code for the
* {@link Model}. The input to the callback is a struct with many
* properties that depend on the attributes of the primitive. This shader code
* is automatically generated by this stage.
* The vertical exaggeration pipeline stage transforms the vertex
* positions based on the values of {@link Scene#verticalExaggeration} and
* {@link Scene#verticalExaggerationRelativeHeight}
*
* @namespace VerticalExaggerationPipelineStage
*
Expand All @@ -20,7 +18,7 @@ const VerticalExaggerationPipelineStage = {
const scratchExaggerationUniform = new Cartesian2();

/**
* Add vertical exaggeration to a shader
* Add defines and uniforms for vertical exaggeration calculations in the vertex shader
*
* @param {PrimitiveRenderResources} renderResources The render resources for the primitive
* @param {ModelComponents.Primitive} primitive The primitive to be rendered
Expand Down
47 changes: 46 additions & 1 deletion packages/engine/Specs/Core/TaskProcessorSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { FeatureDetection, RuntimeError, TaskProcessor } from "../../index.js";
import {
buildModuleUrl,
FeatureDetection,
RuntimeError,
TaskProcessor,
} from "../../index.js";

import absolutize from "../../../../Specs/absolutize.js";

Expand Down Expand Up @@ -60,6 +65,46 @@ describe("Core/TaskProcessor", function () {
);
});

it("when workers loaded via module ID and it is cross-origin, loads worker with appropriate shim", async function () {
// Setup a cross origin BASE_URL
const oldCESIUM_BASE_URL = window.CESIUM_BASE_URL;
window.CESIUM_BASE_URL = "http://test.com/source/";
buildModuleUrl._clearBaseResource();

const blobSpy = spyOn(window, "Blob").and.callThrough();

// Provide just the module ID, as is prevalent in the codebase
taskProcessor = new TaskProcessor("transferTypedArrayTest");
// Create the worker, but don't execute the task this frame
taskProcessor._activeTasks = taskProcessor._maximumActiveTasks;

await taskProcessor.scheduleTask();

expect(blobSpy).toHaveBeenCalledWith(
[`import "http://test.com/source/Workers/transferTypedArrayTest.js";`],
{ type: "application/javascript" }
);

// Reset old values for BASE_URL
window.CESIUM_BASE_URL = oldCESIUM_BASE_URL;
buildModuleUrl._clearBaseResource();
});

it("when provided a cross-origin URI, loads worker with appropriate shim", async function () {
const blobSpy = spyOn(window, "Blob").and.callThrough();

taskProcessor = new TaskProcessor("http://test.com/Workers/testing.js");
// Create the worker, but don't execute the task this frame
taskProcessor._activeTasks = taskProcessor._maximumActiveTasks;

await taskProcessor.scheduleTask();

expect(blobSpy).toHaveBeenCalledWith(
[`import "http://test.com/Workers/testing.js";`],
{ type: "application/javascript" }
);
});

it("can be destroyed", function () {
taskProcessor = new TaskProcessor(
absolutize("../Specs/Build/TestWorkers/returnParameters.js")
Expand Down

0 comments on commit b94ffb7

Please sign in to comment.