From 664dbe1ba80fc99a4e7cceba5d53d32b44a5c641 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 29 Mar 2019 23:06:01 -0400 Subject: [PATCH 1/4] Most detailed fix --- Source/Scene/Scene.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 41f722c9e681..7e62a05440e3 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -3981,6 +3981,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 after viewer._onTick and before 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 undefined if there were no intersections. The intersected object has a primitive @@ -4064,9 +4077,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); - }); + })); }; /** @@ -4093,9 +4106,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(); @@ -4290,13 +4303,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; - }); + })); }; /** @@ -4342,13 +4355,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; - }); + })); }; /** From 5fc443d5dbae031b2d4440a1602047f465712244 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 29 Mar 2019 23:13:10 -0400 Subject: [PATCH 2/4] CHANGES --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index d0c615683734..dbd45fcd57bb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ for pitches close to +/- 90°. [#7654](https://github.com/AnalyticalGraphicsInc/ * Fixed a type of crash caused by the camera being rotated through terrain. [#6783](https://github.com/AnalyticalGraphicsInc/cesium/issues/6783) * Fixed an error in `Resource` when used with template replacements using numeric keys. [#7668](https://github.com/AnalyticalGraphicsInc/cesium/pull/7668) * Fixed an error in `Cesium3DTilePointFeature` where `anchorLineColor` used the same color Instance instead of cloning the color [#7686](https://github.com/AnalyticalGraphicsInc/cesium/pull/7686) +* 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.55 - 2019-03-01 From 9eeb33fd364b263f492f33e36fd324f7103d7e02 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 29 Mar 2019 23:23:14 -0400 Subject: [PATCH 3/4] Tweak comment --- Source/Scene/Scene.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 7e62a05440e3..7319c152beb3 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -3983,7 +3983,7 @@ define([ function deferPromiseUntilPostRender(scene, promise) { // Resolve promise after scene's postRender in case entities are created when the promise resolves. - // Entities can't be created after viewer._onTick and before viewer._postRender. + // 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() { From 8cea930734191f633e09565bb4d04c669d18eca7 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 4 Apr 2019 15:12:50 -0400 Subject: [PATCH 4/4] Remove duplicate CHANGES.md entry [skip ci] --- CHANGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e40b4565a87a..cd1d736cbe81 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,7 +39,6 @@ Change Log * Fixed `HeadingPitchRoll.pitch` being `NaN` when using `.fromQuaternion` due to a rounding error for pitches close to +/- 90°. [#7654](https://github.com/AnalyticalGraphicsInc/cesium/pull/7654) * Fixed a type of crash caused by the camera being rotated through terrain. [#6783](https://github.com/AnalyticalGraphicsInc/cesium/issues/6783) * Fixed an error in `Resource` when used with template replacements using numeric keys. [#7668](https://github.com/AnalyticalGraphicsInc/cesium/pull/7668) -* Fixed an error in `Cesium3DTilePointFeature` where `anchorLineColor` used the same color Instance instead of cloning the color [#7686](https://github.com/AnalyticalGraphicsInc/cesium/pull/7686) * Fixed an error in `Cesium3DTilePointFeature` where `anchorLineColor` used the same color instance instead of cloning the color [#7686](https://github.com/AnalyticalGraphicsInc/cesium/pull/7686) ### 1.55 - 2019-03-01