From adc7272e97599642cc39e5535372ab2fa2c2cddc Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Tue, 17 Apr 2018 11:37:25 -0400 Subject: [PATCH] Fix polyline update and removal bookkeeping Fixes #4983. PolylineCollection stores a list of polylines that are waiting to be updated in the next render pass. However, if a polyline is both updated _and_ removed in the same synchronous execution sequence, _and_ the polyline is near the end of the collection's internal `this._polylines` list, it's possible for the PolylineCollection to effectively read off the end of the array, causing an error "Batch Table instanceIndex out of range". This is resolved by ensuring that removing a polyline from the collection also removes it from the list of polylines waiting to be updated. --- Source/Scene/PolylineCollection.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Scene/PolylineCollection.js b/Source/Scene/PolylineCollection.js index 936744c6ae0b..7d27e2b55403 100644 --- a/Source/Scene/PolylineCollection.js +++ b/Source/Scene/PolylineCollection.js @@ -299,6 +299,12 @@ define([ PolylineCollection.prototype.remove = function(polyline) { if (this.contains(polyline)) { this._polylines[polyline._index] = undefined; // Removed later + + var polylineUpdateIndex = this._polylinesToUpdate.indexOf(polyline); + if(this._polylinesToUpdate.length && polylineUpdateIndex >= 0) { + this._polylinesToUpdate.splice(polylineUpdateIndex, 1); + } + this._polylinesRemoved = true; this._createVertexArray = true; this._createBatchTable = true;