Skip to content

Commit

Permalink
Fix race condition in fog terrain sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed May 3, 2021
1 parent 8e4214f commit e818766
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class Transform {
weightSum += weight;
}

if (weightSum === 0) return 0;
if (weightSum === 0) return NaN;
return elevationSum / weightSum;
}

Expand Down
12 changes: 9 additions & 3 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2806,10 +2806,16 @@ class Map extends Camera {
const timeoutElapsed = ignoreTimeout || timeStamp - this._averageElevationLastSampledAt > AVERAGE_ELEVATION_SAMPLING_INTERVAL;

if (timeoutElapsed && !this._averageElevation.isEasing(timeStamp)) {
this._averageElevationLastSampledAt = timeStamp;

const currentElevation = this.transform.averageElevation;
const newElevation = this.transform.sampleAverageElevation();
let newElevation = this.transform.sampleAverageElevation();

// New elevation is NaN if no terrain tiles were available
if (isNaN(newElevation)) {
newElevation = 0;
} else {
// Don't activate the timeout if no data was available
this._averageElevationLastSampledAt = timeStamp;
}
const elevationChange = Math.abs(currentElevation - newElevation);

if (elevationChange > AVERAGE_ELEVATION_EASE_THRESHOLD) {
Expand Down

0 comments on commit e818766

Please sign in to comment.