3.3.2版本的 instantiateObj方法
obj.node.isChildOf(this.parent)
我碰到了obj.node为空的时候,导致程序异常
增加空判断就解决了。
源代码
if (legacyCC.Class._isCCClass(ctor)) {
if (this.parent) {
if (this.parent instanceof legacyCC.Component) {
if (obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component) {
return this.getObjRef(obj);
}
} else if (this.parent instanceof legacyCC._BaseNode) {
if (obj instanceof legacyCC._BaseNode) {
if (!obj.isChildOf(this.parent)) {
// should not clone other nodes if not descendant
return this.getObjRef(obj);
}
} else if (obj instanceof legacyCC.Component) {
if (!obj.node.isChildOf(this.parent)) {
// should not clone other component if not descendant
return this.getObjRef(obj);
}
}
}
}
createCode = new Declaration(LOCAL_OBJ, `new ${this.getFuncModule(ctor, true)}()`);
}
修改后代码
if (legacyCC.Class._isCCClass(ctor)) {
if (this.parent) {
if (this.parent instanceof legacyCC.Component) {
if (obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component) {
return this.getObjRef(obj);
}
} else if (this.parent instanceof legacyCC._BaseNode) {
if (obj instanceof legacyCC._BaseNode) {
if (!obj.isChildOf(this.parent)) {
// should not clone other nodes if not descendant
return this.getObjRef(obj);
}
} else if (obj instanceof legacyCC.Component) {
if (obj.node && !obj.node.isChildOf(this.parent)) {
// should not clone other component if not descendant
return this.getObjRef(obj);
}
}
}
}
createCode = new Declaration(LOCAL_OBJ, `new ${this.getFuncModule(ctor, true)}()`);
}