mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
destroyed object should be nullify when instantiating (+1 squashed commit)
Squashed commits: [50e59fb] update package.json
This commit is contained in:
+23
-23
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -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",
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user