Browse Source

KeyframeTrack: Don't overwrite inputs to optimize()

Don McCurdy 5 years ago
parent
commit
845b2ae328
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/animation/KeyframeTrack.js

+ 8 - 2
src/animation/KeyframeTrack.js

@@ -347,8 +347,9 @@ Object.assign( KeyframeTrack.prototype, {
 	// (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
 	optimize: function () {
 
-		var times = this.times,
-			values = this.values,
+		// times or values may be shared with other tracks, so overwriting is unsafe
+		var times = AnimationUtils.arraySlice( this.times ),
+			values = AnimationUtils.arraySlice( this.values ),
 			stride = this.getValueSize(),
 
 			smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
@@ -443,6 +444,11 @@ Object.assign( KeyframeTrack.prototype, {
 			this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
 			this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
 
+		} else {
+
+			this.times = times;
+			this.values = values;
+
 		}
 
 		return this;