Skip to content

Commit 502f34a

Browse files
authoredApr 4, 2019
Merge pull request #7690 from AnalyticalGraphicsInc/most-detailed-fix
clampToHeightMostDetailed fix
2 parents dd9756d + 8cea930 commit 502f34a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed
 

‎CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Change Log
22
==========
33

4+
### 1.57 - 2019-05-01
5+
6+
##### Fixes :wrench:
7+
8+
* 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)
9+
410
### 1.56.1 - 2019-04-02
511

612
##### Additions :tada:

‎Source/Scene/Scene.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -3979,6 +3979,19 @@ define([
39793979
return getRayIntersections(scene, ray, limit, objectsToExclude, width, requirePosition, asynchronous);
39803980
}
39813981

3982+
function deferPromiseUntilPostRender(scene, promise) {
3983+
// Resolve promise after scene's postRender in case entities are created when the promise resolves.
3984+
// Entities can't be created between viewer._onTick and viewer._postRender.
3985+
var deferred = when.defer();
3986+
promise.then(function(result) {
3987+
var removeCallback = scene.postRender.addEventListener(function() {
3988+
deferred.resolve(result);
3989+
removeCallback();
3990+
});
3991+
});
3992+
return deferred.promise;
3993+
}
3994+
39823995
/**
39833996
* Returns an object containing the first object intersected by the ray and the position of intersection,
39843997
* or <code>undefined</code> if there were no intersections. The intersected object has a <code>primitive</code>
@@ -4062,9 +4075,9 @@ define([
40624075
var that = this;
40634076
ray = Ray.clone(ray);
40644077
objectsToExclude = defined(objectsToExclude) ? objectsToExclude.slice() : objectsToExclude;
4065-
return launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
4078+
return deferPromiseUntilPostRender(this, launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
40664079
return pickFromRay(that, ray, objectsToExclude, width, false, true);
4067-
});
4080+
}));
40684081
};
40694082

40704083
/**
@@ -4091,9 +4104,9 @@ define([
40914104
var that = this;
40924105
ray = Ray.clone(ray);
40934106
objectsToExclude = defined(objectsToExclude) ? objectsToExclude.slice() : objectsToExclude;
4094-
return launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
4107+
return deferPromiseUntilPostRender(this, launchAsyncRayPick(this, ray, objectsToExclude, width, function() {
40954108
return drillPickFromRay(that, ray, limit, objectsToExclude, width, false, true);
4096-
});
4109+
}));
40974110
};
40984111

40994112
var scratchSurfacePosition = new Cartesian3();
@@ -4282,13 +4295,13 @@ define([
42824295
for (var i = 0; i < length; ++i) {
42834296
promises[i] = sampleHeightMostDetailed(this, positions[i], objectsToExclude, width);
42844297
}
4285-
return when.all(promises).then(function(heights) {
4298+
return deferPromiseUntilPostRender(this, when.all(promises).then(function(heights) {
42864299
var length = heights.length;
42874300
for (var i = 0; i < length; ++i) {
42884301
positions[i].height = heights[i];
42894302
}
42904303
return positions;
4291-
});
4304+
}));
42924305
};
42934306

42944307
/**
@@ -4334,13 +4347,13 @@ define([
43344347
for (var i = 0; i < length; ++i) {
43354348
promises[i] = clampToHeightMostDetailed(this, cartesians[i], objectsToExclude, width, cartesians[i]);
43364349
}
4337-
return when.all(promises).then(function(clampedCartesians) {
4350+
return deferPromiseUntilPostRender(this, when.all(promises).then(function(clampedCartesians) {
43384351
var length = clampedCartesians.length;
43394352
for (var i = 0; i < length; ++i) {
43404353
cartesians[i] = clampedCartesians[i];
43414354
}
43424355
return cartesians;
4343-
});
4356+
}));
43444357
};
43454358

43464359
/**

0 commit comments

Comments
 (0)
Please sign in to comment.