Skip to content

Commit

Permalink
Merge pull request #7690 from AnalyticalGraphicsInc/most-detailed-fix
Browse files Browse the repository at this point in the history
clampToHeightMostDetailed fix
  • Loading branch information
lilleyse authored Apr 4, 2019
2 parents dd9756d + 8cea930 commit 502f34a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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

0 comments on commit 502f34a

Please sign in to comment.