@@ -3979,6 +3979,19 @@ define([
3979
3979
return getRayIntersections ( scene , ray , limit , objectsToExclude , width , requirePosition , asynchronous ) ;
3980
3980
}
3981
3981
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
+
3982
3995
/**
3983
3996
* Returns an object containing the first object intersected by the ray and the position of intersection,
3984
3997
* or <code>undefined</code> if there were no intersections. The intersected object has a <code>primitive</code>
@@ -4062,9 +4075,9 @@ define([
4062
4075
var that = this ;
4063
4076
ray = Ray . clone ( ray ) ;
4064
4077
objectsToExclude = defined ( objectsToExclude ) ? objectsToExclude . slice ( ) : objectsToExclude ;
4065
- return launchAsyncRayPick ( this , ray , objectsToExclude , width , function ( ) {
4078
+ return deferPromiseUntilPostRender ( this , launchAsyncRayPick ( this , ray , objectsToExclude , width , function ( ) {
4066
4079
return pickFromRay ( that , ray , objectsToExclude , width , false , true ) ;
4067
- } ) ;
4080
+ } ) ) ;
4068
4081
} ;
4069
4082
4070
4083
/**
@@ -4091,9 +4104,9 @@ define([
4091
4104
var that = this ;
4092
4105
ray = Ray . clone ( ray ) ;
4093
4106
objectsToExclude = defined ( objectsToExclude ) ? objectsToExclude . slice ( ) : objectsToExclude ;
4094
- return launchAsyncRayPick ( this , ray , objectsToExclude , width , function ( ) {
4107
+ return deferPromiseUntilPostRender ( this , launchAsyncRayPick ( this , ray , objectsToExclude , width , function ( ) {
4095
4108
return drillPickFromRay ( that , ray , limit , objectsToExclude , width , false , true ) ;
4096
- } ) ;
4109
+ } ) ) ;
4097
4110
} ;
4098
4111
4099
4112
var scratchSurfacePosition = new Cartesian3 ( ) ;
@@ -4282,13 +4295,13 @@ define([
4282
4295
for ( var i = 0 ; i < length ; ++ i ) {
4283
4296
promises [ i ] = sampleHeightMostDetailed ( this , positions [ i ] , objectsToExclude , width ) ;
4284
4297
}
4285
- return when . all ( promises ) . then ( function ( heights ) {
4298
+ return deferPromiseUntilPostRender ( this , when . all ( promises ) . then ( function ( heights ) {
4286
4299
var length = heights . length ;
4287
4300
for ( var i = 0 ; i < length ; ++ i ) {
4288
4301
positions [ i ] . height = heights [ i ] ;
4289
4302
}
4290
4303
return positions ;
4291
- } ) ;
4304
+ } ) ) ;
4292
4305
} ;
4293
4306
4294
4307
/**
@@ -4334,13 +4347,13 @@ define([
4334
4347
for ( var i = 0 ; i < length ; ++ i ) {
4335
4348
promises [ i ] = clampToHeightMostDetailed ( this , cartesians [ i ] , objectsToExclude , width , cartesians [ i ] ) ;
4336
4349
}
4337
- return when . all ( promises ) . then ( function ( clampedCartesians ) {
4350
+ return deferPromiseUntilPostRender ( this , when . all ( promises ) . then ( function ( clampedCartesians ) {
4338
4351
var length = clampedCartesians . length ;
4339
4352
for ( var i = 0 ; i < length ; ++ i ) {
4340
4353
cartesians [ i ] = clampedCartesians [ i ] ;
4341
4354
}
4342
4355
return cartesians ;
4343
- } ) ;
4356
+ } ) ) ;
4344
4357
} ;
4345
4358
4346
4359
/**
0 commit comments