Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clampToHeightMostDetailed fix #7690

Merged
merged 5 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
==========

### 1.57 - 2019-05-01

##### Fixes :wrench:

* Fixed an error where `clampToHeightMostDetailed` or `sampleHeightMostDetailed` would crash if entities were created when the promise resolved. [#7690](https://github.com/AnalyticalGraphicsInc/cesium/pull/7690)

### 1.56.1 - 2019-04-02

##### Additions :tada:
Expand Down
29 changes: 21 additions & 8 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -3979,6 +3979,19 @@ define([
return getRayIntersections(scene, ray, limit, objectsToExclude, width, requirePosition, asynchronous);
}

function deferPromiseUntilPostRender(scene, promise) {
// Resolve promise after scene's postRender in case entities are created when the promise resolves.
// Entities can't be created between viewer._onTick and viewer._postRender.
var deferred = when.defer();
promise.then(function(result) {
var removeCallback = scene.postRender.addEventListener(function() {
deferred.resolve(result);
removeCallback();
});
});
return deferred.promise;
}

/**
* Returns an object containing the first object intersected by the ray and the position of intersection,
* or <code>undefined</code> if there were no intersections. The intersected object has a <code>primitive</code>
Expand Down Expand Up @@ -4062,9 +4075,9 @@ define([
var that = this;
ray = Ray.clone(ray);
objectsToExclude = defined(objectsToExclude) ? objectsToExclude.slice() : objectsToExclude;
return launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
return deferPromiseUntilPostRender(this, launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
return pickFromRay(that, ray, objectsToExclude, width, false, true);
});
}));
};

/**
Expand All @@ -4091,9 +4104,9 @@ define([
var that = this;
ray = Ray.clone(ray);
objectsToExclude = defined(objectsToExclude) ? objectsToExclude.slice() : objectsToExclude;
return launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
return deferPromiseUntilPostRender(this, launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
return drillPickFromRay(that, ray, limit, objectsToExclude, width, false, true);
});
}));
};

var scratchSurfacePosition = new Cartesian3();
Expand Down Expand Up @@ -4282,13 +4295,13 @@ define([
for (var i = 0; i < length; ++i) {
promises[i] = sampleHeightMostDetailed(this, positions[i], objectsToExclude, width);
}
return when.all(promises).then(function(heights) {
return deferPromiseUntilPostRender(this, when.all(promises).then(function(heights) {
var length = heights.length;
for (var i = 0; i < length; ++i) {
positions[i].height = heights[i];
}
return positions;
});
}));
};

/**
Expand Down Expand Up @@ -4334,13 +4347,13 @@ define([
for (var i = 0; i < length; ++i) {
promises[i] = clampToHeightMostDetailed(this, cartesians[i], objectsToExclude, width, cartesians[i]);
}
return when.all(promises).then(function(clampedCartesians) {
return deferPromiseUntilPostRender(this, when.all(promises).then(function(clampedCartesians) {
var length = clampedCartesians.length;
for (var i = 0; i < length; ++i) {
cartesians[i] = clampedCartesians[i];
}
return cartesians;
});
}));
};

/**
Expand Down