diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 7d43d77be1..3e940f703b 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -540,29 +540,29 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ } }, - _replaceScene: CC_EDITOR && function (scene) { - if (this._scene) { - this._scene._activate(false); - } - if (this._runningScene) { - this._runningScene.onExit(); - } - - this.emit(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, scene); - - // ensure scene initialized - scene._load(); - - // replace scene - this._scene = scene; - this._runningScene = scene._sgNode; - - // Activate - cc.renderer.childrenOrderDirty = true; - scene._sgNode.onEnter(); - scene._activate(); - this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); - }, + //_replaceScene: CC_EDITOR && function (scene) { + // if (this._scene) { + // this._scene._activate(false); + // } + // if (this._runningScene) { + // this._runningScene.onExit(); + // } + // + // this.emit(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, scene); + // + // // ensure scene initialized + // scene._load(); + // + // // replace scene + // this._scene = scene; + // this._runningScene = scene._sgNode; + // + // // Activate + // cc.renderer.childrenOrderDirty = true; + // scene._sgNode.onEnter(); + // scene._activate(); + // this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); + //}, // @Scene loading section diff --git a/cocos2d/core/platform/instantiate.js b/cocos2d/core/platform/instantiate.js index 1d5df481be..d3b1bbd7b4 100644 --- a/cocos2d/core/platform/instantiate.js +++ b/cocos2d/core/platform/instantiate.js @@ -187,6 +187,10 @@ function instantiateObj (obj, parent, ownerObj, ownerKey) { return clone; } + if ( !cc.isValid(obj) ) { + return null; + } + if (obj instanceof cc.Asset) { // 所有资源直接引用,不需要拷贝 return obj; diff --git a/package.json b/package.json index b0ca062afa..3bb13b13cf 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "browserify": "11.2.0", "chalk": "1.1.0", "del": "1.2.0", - "event-stream": "3.3.1", + "event-stream": "3.3.2", "fire-fs": "0.2.1", "gulp": "3.9.0", "gulp-cached": "1.1.0", @@ -29,7 +29,7 @@ "gulp-sourcemaps": "1.5.2", "gulp-uglify": "1.2.0", "gulp-util": "3.0.6", - "jshint-stylish": "2.0.1", + "jshint-stylish": "2.1.0", "require-dir": "0.3.0", "vinyl": "1.1.0", "vinyl-buffer": "1.0.0", diff --git a/test/qunit/unit/test-instantiate.js b/test/qunit/unit/test-instantiate.js index 90ef53fce3..bdd6d05b2d 100644 --- a/test/qunit/unit/test-instantiate.js +++ b/test/qunit/unit/test-instantiate.js @@ -181,6 +181,27 @@ cc.js.unregisterClass(Script); }); + test('destroyed', function () { + var Script = cc.Class({ + extends: cc.Component, + properties: { + compRef: null + } + }); + + var node = new cc.Node(); + var comp = node.addComponent(Script); + var otherComp = node.addComponent(cc.Sprite); + comp.compRef = otherComp; + otherComp.destroy(); + + cc.Object._deferredDestroy(); + + var clone = cc.instantiate(node); + + strictEqual(clone.getComponent(Script).compRef, null, 'deleted object should be nullify'); + }); + test('redirect reference', function () { var Script = cc.Class({ name: '2154648724566',