Skip to content

Commit 17236a3

Browse files
author
Samuel Vargas
committed
Replace defined checks for polyline with isDestroyed getter, combine for loops [skip ci]
1 parent 60da6a5 commit 17236a3

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Source/Scene/Polyline.js

+13
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ import Material from './Material.js';
285285
}
286286
},
287287

288+
/**
289+
* Gets the destruction status of Polyline
290+
* @memberof Polyline.prototype
291+
* @type {Boolean}
292+
* @default undefined
293+
* @private
294+
*/
295+
isDestroyed : {
296+
get : function() {
297+
return !defined(this.polylineCollection);
298+
}
299+
},
300+
288301
/**
289302
* Gets or sets the condition specifying at what distance from the camera that this polyline will be displayed.
290303
* @memberof Polyline.prototype

Source/Scene/PolylineCollection.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ import SceneMode from './SceneMode.js';
257257
*/
258258
PolylineCollection.prototype.remove = function(polyline) {
259259
if (this.contains(polyline)) {
260-
this._polylines[polyline._index] = undefined; // Removed later
261260
this._polylinesRemoved = true;
262261
this._createVertexArray = true;
263262
this._createBatchTable = true;
@@ -1046,13 +1045,12 @@ import SceneMode from './SceneMode.js';
10461045
var definedPolylines = [];
10471046
var polyIndex = 0;
10481047
var polyline;
1049-
var i;
10501048

10511049
var length = collection._polylines.length;
10521050
var definedPolylinesToUpdate = [];
1053-
for (i = 0; i < length; ++i) {
1051+
for (var i = 0; i < length; ++i) {
10541052
polyline = collection._polylines[i];
1055-
if (defined(polyline) && defined(polyline._polylineCollection)) {
1053+
if (!polyline.isDestroyed) {
10561054
polyline._index = polyIndex++;
10571055
definedPolylinesToUpdate.push(polyline);
10581056
definedPolylines.push(polyline);
@@ -1068,7 +1066,7 @@ import SceneMode from './SceneMode.js';
10681066
var polylines = collection._polylines;
10691067
var length = polylines.length;
10701068
for ( var i = 0; i < length; ++i) {
1071-
if (defined(polylines[i])) {
1069+
if (!polylines[i].isDestroyed) {
10721070
var bucket = polylines[i]._bucket;
10731071
if (defined(bucket)) {
10741072
bucket.shaderProgram = bucket.shaderProgram && bucket.shaderProgram.destroy();
@@ -1097,7 +1095,7 @@ import SceneMode from './SceneMode.js';
10971095
var polylines = collection._polylines;
10981096
var length = polylines.length;
10991097
for ( var i = 0; i < length; ++i) {
1100-
if (defined(polylines[i])) {
1098+
if (polylines[i].isDestroyed) {
11011099
polylines[i]._destroy();
11021100
}
11031101
}

0 commit comments

Comments
 (0)