mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #2374 from CocosAss/master
Initial fix node Hierarchy change when it is deactivating issue
This commit is contained in:
@@ -410,6 +410,7 @@ if (CC_DEBUG) {
|
||||
"3818": "Failed to read or parse project.json", //_loadConfig
|
||||
"3819": "Warning: target element is not a DIV or CANVAS", //_initRenderer
|
||||
"3820": "The renderer doesn't support the renderMode %s", //_initRenderer
|
||||
"3821": "Cannot change hierarchy while activating or deactivating nodes.",
|
||||
//Animation: 3900
|
||||
"3900": "Invalid clip to add", //addClip
|
||||
"3901": "Invalid clip to remove", //removeClip
|
||||
|
||||
@@ -33,6 +33,7 @@ var eventManager = require('../event-manager');
|
||||
var JS = cc.js;
|
||||
var Destroying = Flags.Destroying;
|
||||
var DontDestroy = Flags.DontDestroy;
|
||||
var Deactivating = Flags.Deactivating;
|
||||
|
||||
var CHILD_ADDED = 'child-added';
|
||||
var CHILD_REMOVED = 'child-removed';
|
||||
@@ -366,10 +367,16 @@ var BaseNode = cc.Class({
|
||||
|
||||
this._onSetParent(value);
|
||||
|
||||
if (CC_DEBUG && (this._objFlags & Deactivating)) {
|
||||
cc.errorID(3821);
|
||||
}
|
||||
if (value) {
|
||||
if (!CC_JSB) {
|
||||
eventManager._setDirtyForNode(this);
|
||||
}
|
||||
if (CC_DEBUG && (value._objFlags & Deactivating)) {
|
||||
cc.errorID(3821);
|
||||
}
|
||||
value._children.push(this);
|
||||
value.emit(CHILD_ADDED, this);
|
||||
}
|
||||
@@ -551,6 +558,10 @@ var BaseNode = cc.Class({
|
||||
if (!this._parent) {
|
||||
return;
|
||||
}
|
||||
if ((this._parent._objFlags & Deactivating)) {
|
||||
cc.errorID(3821);
|
||||
return;
|
||||
}
|
||||
var siblings = this._parent._children;
|
||||
index = index !== -1 ? index : siblings.length - 1;
|
||||
var oldIndex = siblings.indexOf(this);
|
||||
|
||||
@@ -165,6 +165,85 @@ test('disable component during onEnable', function () {
|
||||
childComp.onEnable.once('could re-enable component');
|
||||
});
|
||||
|
||||
test('change parent during onDisable', function () {
|
||||
|
||||
var rootNode , preNode , testNode , child , childComp;
|
||||
|
||||
var vendorError = cc.errorID;
|
||||
cc.errorID = new Callback().enable();
|
||||
|
||||
//Pattern one : the Hierarchy change during onDisable
|
||||
|
||||
var nodes1 = createNodes({
|
||||
preNode: {},
|
||||
testNode: {
|
||||
comps: cc.Component,
|
||||
},
|
||||
});
|
||||
rootNode = nodes1.root;
|
||||
preNode = nodes1.preNode;
|
||||
testNode = nodes1.testNode;
|
||||
testNodeComp = nodes1.testNodeComps[0];
|
||||
|
||||
testNodeComp.onDisable = function() {
|
||||
testNode.parent = preNode;
|
||||
};
|
||||
|
||||
nodes1.attachToScene();
|
||||
|
||||
testNode.active = false;
|
||||
cc.errorID.once('Should report error when changing target node\'s parent during its deactivation');
|
||||
|
||||
//Pattern two : the Hierarchy change during onDisable
|
||||
|
||||
var nodes2 = createNodes({
|
||||
preNode: {},
|
||||
testNode: {
|
||||
comps: cc.Component,
|
||||
},
|
||||
});
|
||||
rootNode = nodes2.root;
|
||||
preNode = nodes2.preNode;
|
||||
testNode = nodes2.testNode;
|
||||
testNodeComp = nodes2.testNodeComps[0];
|
||||
|
||||
testNodeComp.onDisable = function() {
|
||||
preNode.parent = testNode;
|
||||
}
|
||||
|
||||
nodes2.attachToScene();
|
||||
|
||||
testNode.active = false;
|
||||
cc.errorID.once('Should report error when append new child to a target node during its deactivation');
|
||||
|
||||
//Pattern three : the Hierarchy change during onDisable
|
||||
|
||||
var nodes3 = createNodes({
|
||||
testNode: {
|
||||
child1: {
|
||||
comps: cc.Component,
|
||||
},
|
||||
child2: {}
|
||||
},
|
||||
});
|
||||
rootNode = nodes3.root;
|
||||
testNode = nodes3.testNode;
|
||||
child1 = nodes3.child1;
|
||||
child1Comp = nodes3.child1Comps[0];
|
||||
child2 = nodes3.child2;
|
||||
|
||||
child1Comp.onDisable = function() {
|
||||
child1.setSiblingIndex(1);
|
||||
};
|
||||
|
||||
nodes3.attachToScene();
|
||||
|
||||
testNode.active = false;
|
||||
cc.errorID.once('Should report error when setting node\'s sibling index during its parent\'s deactivation');
|
||||
|
||||
cc.errorID = vendorError;
|
||||
});
|
||||
|
||||
(function () {
|
||||
|
||||
// Test deactivate during activating or conversely
|
||||
|
||||
Reference in New Issue
Block a user