fix(mission): 修复组件生命周期与节点安全访问问题

- 移除 MissionCardComp.onLoad 中自动触发的 onMissionStart,改为由 MissionComp 通过 scheduleOnce 事件驱动,确保组件初始化顺序
- 在设置节点 active 属性前增加节点有效性检查,避免节点已销毁时访问导致的错误
- 在更新计时器 UI 时增加节点和组件存在性检查,防止空引用异常
This commit is contained in:
panw
2026-05-08 15:09:06 +08:00
parent 07aec09283
commit 64168e576f
2 changed files with 30 additions and 9 deletions

View File

@@ -167,7 +167,7 @@ export class MissionCardComp extends CCComp {
this.cacheCardComps();
this.layoutCardSlots();
this.initCardsPanelPos();
this.onMissionStart();
// this.onMissionStart(); // 移除 onLoad 自动触发,改为事件驱动
mLogger.log(this.debugMode, "MissionCardComp", "onLoad init", {
slots: this.cardComps.length,
poolLv: this.poolLv
@@ -231,7 +231,9 @@ export class MissionCardComp extends CCComp {
// this.resetButtonScale(this.cards_up);
this.updateCoinAndCostUI();
this.updateHeroNumUI(false, false);
this.node.active = true;
if (this.node && this.node.isValid) {
this.node.active = true;
}
const cards = this.buildDrawCards();
this.dispatchCardsToSlots(cards);
mLogger.log(this.debugMode, "MissionCardComp", "mission start", {
@@ -243,7 +245,9 @@ export class MissionCardComp extends CCComp {
onMissionEnd() {
this.clearAllCards();
this.clearHeroInfoPanels();
this.node.active = false;
if (this.node && this.node.isValid) {
this.node.active = false;
}
}
start() {
@@ -264,7 +268,9 @@ export class MissionCardComp extends CCComp {
/** 关闭面板(不销毁数据模型,仅隐藏) */
close() {
this.node.active = false;
if (this.node && this.node.isValid) {
this.node.active = false;
}
}
// ======================== 事件绑定 ========================