mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 11:02:40 +08:00
Merge pull request #144 from jareguo/master
child sg-node should also be released after node destoryed
This commit is contained in:
@@ -376,6 +376,10 @@ var Node = cc.Class({
|
||||
this._parent = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._sgNode.release();
|
||||
this._sgNode = null;
|
||||
}
|
||||
},
|
||||
|
||||
// COMPONENT
|
||||
|
||||
@@ -158,6 +158,7 @@ module.exports = function (properties, className) {
|
||||
}
|
||||
else if (typeof val === 'function') {
|
||||
if (cc.isChildClassOf(val, cc.ValueType)) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
val = {
|
||||
default: new val(),
|
||||
type: val
|
||||
|
||||
@@ -392,3 +392,25 @@ test('attach events', function () {
|
||||
cc.engine.off('node-attach-to-scene', onAttach);
|
||||
cc.engine.off('node-detach-from-scene', onDetach);
|
||||
});
|
||||
|
||||
test('release sg node', function () {
|
||||
var parent = new cc.Node();
|
||||
var child = new cc.Node();
|
||||
child.parent = parent;
|
||||
|
||||
var childReleased = false;
|
||||
var parentReleased = false;
|
||||
|
||||
child._sgNode.release = function () {
|
||||
childReleased = true;
|
||||
};
|
||||
parent._sgNode.release = function () {
|
||||
parentReleased = true;
|
||||
};
|
||||
|
||||
parent.destroy();
|
||||
cc.Object._deferredDestroy();
|
||||
|
||||
strictEqual(parentReleased, true, 'should release parent sg node');
|
||||
strictEqual(childReleased, true, 'should release child sg node');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user