From a62bfdb7684024fbab22b8577d254832d1a5c8d0 Mon Sep 17 00:00:00 2001 From: zhuxuguang <247274249@qq.com> Date: Tue, 22 Jan 2019 17:21:55 +0800 Subject: [PATCH] fix some bug --- cocos/3d/framework/model-component.js | 6 +++--- cocos/scene-graph/base-node.ts | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cocos/3d/framework/model-component.js b/cocos/3d/framework/model-component.js index 5195ebde8c..1b0d59561b 100644 --- a/cocos/3d/framework/model-component.js +++ b/cocos/3d/framework/model-component.js @@ -175,7 +175,6 @@ export class ModelComponent extends RenderableComponent { this._updateModels(); this._updateCastShadow(); this._updateReceiveShadow(); - this._model.enable = true; } onDisable() { @@ -198,6 +197,7 @@ export class ModelComponent extends RenderableComponent { } else { this._model = this._createModel(); } + this._model.enable = this.enabled; this._model.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition); @@ -235,7 +235,7 @@ export class ModelComponent extends RenderableComponent { } _updateCastShadow() { - if (!this.enabled) + if (!this.enabled || !this._model) return; if (this._shadowCastingMode === ModelShadowCastingMode.Off) { for (let i = 0; i < this._model.subModelNum; ++i) { @@ -253,7 +253,7 @@ export class ModelComponent extends RenderableComponent { } _updateReceiveShadow() { - if (!this.enabled) + if (!this.enabled || !this._model) return; for (let i = 0; i < this._model.subModelNum; ++i) { let subModel = this._model.getSubModel(i); diff --git a/cocos/scene-graph/base-node.ts b/cocos/scene-graph/base-node.ts index f6d5fa4aca..57df433741 100644 --- a/cocos/scene-graph/base-node.ts +++ b/cocos/scene-graph/base-node.ts @@ -286,7 +286,7 @@ export class BaseNode extends CCObject { private static _findChildComponents (children: BaseNode[], constructor, components) { for (const node of children) { - BaseNode._findComponents (node, constructor, components); + BaseNode._findComponents(node, constructor, components); if (node._children.length > 0) { BaseNode._findChildComponents(node._children, constructor, components); } @@ -1058,13 +1058,15 @@ export class BaseNode extends CCObject { return; } - public emit? (type: string, ...args: any[]): void; + public emit?(type: string, ...args: any[]): void; protected _onSetParent (oldParent: this | null) { - if ((oldParent == null || oldParent._scene !== this._parent!._scene) && this._parent!._scene != null) { - this.walk((node) => { - BaseNode._setScene(node); - }); + if (this._parent) { + if ((oldParent == null || oldParent._scene !== this._parent._scene) && this._parent._scene != null) { + this.walk((node) => { + BaseNode._setScene(node); + }); + } } } @@ -1252,11 +1254,11 @@ export class BaseNode extends CCObject { } } - private _onSiblingIndexChanged? (siblingIndex: number): void; + private _onSiblingIndexChanged?(siblingIndex: number): void; - private _registerIfAttached? (attached: boolean): void; + private _registerIfAttached?(attached: boolean): void; - private _checkMultipleComp? (constructor: Function): boolean; + private _checkMultipleComp?(constructor: Function): boolean; private _onPreDestroyBase () { return this._onPreDestroy();