fix(任务组件): 修复PhaseTime可能未初始化的空指针异常

在切换任务阶段时,如果PhaseTime尚未初始化,调用reset方法会导致空指针异常。同样在组件销毁时也需要安全地清理PhaseTime。

- 在data_init中确保PhaseTime被正确初始化
- 在setPhase方法中添加空值检查
- 在reset方法中安全销毁节点并清理PhaseTime引用
This commit is contained in:
panw
2026-05-08 15:51:04 +08:00
parent 64168e576f
commit cc60ebf332

View File

@@ -432,7 +432,9 @@ export class MissionComp extends CCComp {
}
// 重置状态机的计时器
this.PhaseTime.reset();
if (this.PhaseTime) {
this.PhaseTime.reset();
}
switch (targetPhase) {
case MissionPhase.PrepareStart:
@@ -704,6 +706,9 @@ export class MissionComp extends CCComp {
* - 性能监控基准值
*/
data_init(){
if (!this.PhaseTime) {
this.PhaseTime = new Timer(1);
}
smc.mission.play = true;
smc.mission.pause = false;
smc.mission.stop_mon_action = false;
@@ -1053,6 +1058,9 @@ export class MissionComp extends CCComp {
/** ECS 组件移除时销毁节点 */
reset() {
this.node.destroy();
this.PhaseTime = null as any;
if (this.node && this.node.isValid) {
this.node.destroy();
}
}
}