mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 05:01:41 +08:00
Fixed tween destroy memory leak. close #1898
This commit is contained in:
parent
fd77f305d1
commit
f32a416e03
@ -3,6 +3,11 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## 9.3.21 (not released)
|
||||||
|
|
||||||
|
- Fixed memory leaks on Tween destroy
|
||||||
|
- Fixed incorrect export of stage/layer when internal nodes used buffer canvas for rendering
|
||||||
|
|
||||||
## 9.3.20 (2025-03-20)
|
## 9.3.20 (2025-03-20)
|
||||||
|
|
||||||
- Fix text rendering when ellipses are used
|
- Fix text rendering when ellipses are used
|
||||||
|
33
src/Tween.ts
33
src/Tween.ts
@ -200,8 +200,7 @@ export class Tween {
|
|||||||
nodeId = node._id,
|
nodeId = node._id,
|
||||||
easing = config.easing || Easings.Linear,
|
easing = config.easing || Easings.Linear,
|
||||||
yoyo = !!config.yoyo;
|
yoyo = !!config.yoyo;
|
||||||
let duration,
|
let duration, key;
|
||||||
key;
|
|
||||||
|
|
||||||
if (typeof config.duration === 'undefined') {
|
if (typeof config.duration === 'undefined') {
|
||||||
duration = 0.3;
|
duration = 0.3;
|
||||||
@ -268,11 +267,7 @@ export class Tween {
|
|||||||
_addAttr(key, end) {
|
_addAttr(key, end) {
|
||||||
const node = this.node,
|
const node = this.node,
|
||||||
nodeId = node._id;
|
nodeId = node._id;
|
||||||
let diff,
|
let diff, len, trueEnd, trueStart, endRGBA;
|
||||||
len,
|
|
||||||
trueEnd,
|
|
||||||
trueStart,
|
|
||||||
endRGBA;
|
|
||||||
|
|
||||||
// remove conflict from tween map if it exists
|
// remove conflict from tween map if it exists
|
||||||
const tweenId = Tween.tweens[nodeId][key];
|
const tweenId = Tween.tweens[nodeId][key];
|
||||||
@ -352,14 +347,7 @@ export class Tween {
|
|||||||
_tweenFunc(i) {
|
_tweenFunc(i) {
|
||||||
const node = this.node,
|
const node = this.node,
|
||||||
attrs = Tween.attrs[node._id][this._id];
|
attrs = Tween.attrs[node._id][this._id];
|
||||||
let key,
|
let key, attr, start, diff, newVal, n, len, end;
|
||||||
attr,
|
|
||||||
start,
|
|
||||||
diff,
|
|
||||||
newVal,
|
|
||||||
n,
|
|
||||||
len,
|
|
||||||
end;
|
|
||||||
|
|
||||||
for (key in attrs) {
|
for (key in attrs) {
|
||||||
attr = attrs[key];
|
attr = attrs[key];
|
||||||
@ -528,11 +516,26 @@ export class Tween {
|
|||||||
|
|
||||||
this.pause();
|
this.pause();
|
||||||
|
|
||||||
|
// Clean up animation
|
||||||
|
if (this.anim) {
|
||||||
|
this.anim.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up tween entries
|
||||||
for (const key in attrs) {
|
for (const key in attrs) {
|
||||||
delete Tween.tweens[nodeId][key];
|
delete Tween.tweens[nodeId][key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up attrs entry
|
||||||
delete Tween.attrs[nodeId][thisId];
|
delete Tween.attrs[nodeId][thisId];
|
||||||
|
|
||||||
|
// Clean up parent objects if empty
|
||||||
|
if (Object.keys(Tween.tweens[nodeId]).length === 0) {
|
||||||
|
delete Tween.tweens[nodeId];
|
||||||
|
}
|
||||||
|
if (Object.keys(Tween.attrs[nodeId]).length === 0) {
|
||||||
|
delete Tween.attrs[nodeId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
// CORE
|
// CORE
|
||||||
import './unit/Animation-test.ts';
|
import './unit/Animation-test.ts';
|
||||||
|
import './unit/Tween-test.ts';
|
||||||
import './unit/Canvas-test.ts';
|
import './unit/Canvas-test.ts';
|
||||||
import './unit/Container-test.ts';
|
import './unit/Container-test.ts';
|
||||||
import './unit/Context-test.ts';
|
import './unit/Context-test.ts';
|
||||||
|
@ -98,8 +98,8 @@ describe('Tween', function () {
|
|||||||
|
|
||||||
tween.destroy();
|
tween.destroy();
|
||||||
|
|
||||||
assert.equal(Konva.Tween.tweens[circle._id].x, undefined);
|
assert.equal(Konva.Tween.tweens[circle._id], undefined);
|
||||||
assert.equal(Konva.Tween.attrs[circle._id][tween._id], undefined);
|
assert.equal(Konva.Tween.attrs[circle._id], undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
@ -238,7 +238,7 @@ describe('Tween', function () {
|
|||||||
duration: 0.1,
|
duration: 0.1,
|
||||||
onFinish: function () {
|
onFinish: function () {
|
||||||
assert.equal(circle.x(), stage.width() / 2);
|
assert.equal(circle.x(), stage.width() / 2);
|
||||||
assert.equal(Object.keys(Konva.Tween.attrs[circle._id]).length, 0);
|
assert.equal(Konva.Tween.attrs[circle._id], undefined);
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -305,16 +305,10 @@ describe('Tween', function () {
|
|||||||
points: [100, 100, 200, 100, 200, 200, 100, 200],
|
points: [100, 100, 200, 100, 200, 200, 100, 200],
|
||||||
duration: 0.1,
|
duration: 0.1,
|
||||||
onFinish: function () {
|
onFinish: function () {
|
||||||
assert.deepEqual(line.points(), [
|
assert.deepEqual(
|
||||||
100,
|
line.points(),
|
||||||
100,
|
[100, 100, 200, 100, 200, 200, 100, 200]
|
||||||
200,
|
);
|
||||||
100,
|
|
||||||
200,
|
|
||||||
200,
|
|
||||||
100,
|
|
||||||
200,
|
|
||||||
]);
|
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -364,16 +358,10 @@ describe('Tween', function () {
|
|||||||
tween.reverse();
|
tween.reverse();
|
||||||
},
|
},
|
||||||
onReset: function () {
|
onReset: function () {
|
||||||
assert.deepEqual(line.points(), [
|
assert.deepEqual(
|
||||||
100,
|
line.points(),
|
||||||
100,
|
[100, 100, 200, 100, 200, 200, 100, 200]
|
||||||
200,
|
);
|
||||||
100,
|
|
||||||
200,
|
|
||||||
200,
|
|
||||||
100,
|
|
||||||
200,
|
|
||||||
]);
|
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user