From fbab4aaa42f4c20d364f155dd64ad92053f31b9d Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 28 Dec 2015 19:41:00 +0800 Subject: [PATCH] child sg-node should also be released after node destoryed --- cocos2d/core/CCNode.js | 4 ++++ cocos2d/core/platform/preprocess-attrs.js | 1 + test/qunit/unit/test-node.js | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 28a4020b7e..682d6a8f18 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -376,6 +376,10 @@ var Node = cc.Class({ this._parent = null; } } + else { + this._sgNode.release(); + this._sgNode = null; + } }, // COMPONENT diff --git a/cocos2d/core/platform/preprocess-attrs.js b/cocos2d/core/platform/preprocess-attrs.js index e84e3da725..3d8a0224d5 100644 --- a/cocos2d/core/platform/preprocess-attrs.js +++ b/cocos2d/core/platform/preprocess-attrs.js @@ -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 diff --git a/test/qunit/unit/test-node.js b/test/qunit/unit/test-node.js index ee6fc71bb7..2a6068aa82 100644 --- a/test/qunit/unit/test-node.js +++ b/test/qunit/unit/test-node.js @@ -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'); +});