fix(碰撞处理): 增加防御性检查并优化英雄死亡时的碰撞体处理

在SkillView中添加对目标实体是否存在的检查,避免访问已销毁实体
在HeroViewComp中死亡时禁用碰撞体,防止"尸体"参与后续碰撞
This commit is contained in:
walkpan
2026-01-02 15:08:30 +08:00
parent f3039eb47b
commit ed728bd1b9
2 changed files with 12 additions and 0 deletions

View File

@@ -375,6 +375,13 @@ export class HeroViewComp extends CCComp {
this.debugWarn("[HeroViewComp] realDead called but model is null, skipping");
return;
}
// 🔥 方案B治理性措施 - 在销毁实体前先禁用碰撞体,从源头减少"尸体"参与碰撞
const collider = this.getComponent(Collider2D);
if (collider) {
collider.enabled = false;
}
if(this.model.fac === FacSet.HERO){
// 英雄死亡:延迟触发死亡事件
oops.message.dispatchEvent(GameEvent.HeroDead, {

View File

@@ -62,6 +62,11 @@ export class SkillView extends CCComp {
if (oCol.group === seCol.group) return;
// 不是 HeroViewComp直接忽略
if (!targetView) return;
// 🔥 方案A防御性检查 - 在获取model前强制检查ent是否存在
if (!targetView.ent) {
console.warn('[SkillView] onBeginContact targetView.ent为空实体已销毁忽略此次碰撞');
return;
}
let model = targetView.ent.get(HeroAttrsComp);
// console.log(`[skillView] 碰撞3`, oCol.group, seCol.group, model);
if (!model) return;