Skip to content

Commit

Permalink
fix: exception when removing entity inside camera trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
pbosio committed Oct 1, 2020
1 parent 44431e1 commit 981ef95
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/triggers/triggerSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ export class TriggerSystem implements ISystem {
private static removeTriggerFromSystem(wrapper: TriggerWrapper) {
let activeCollisions = wrapper.getActiveCollisions()
for (let i = 0; i < activeCollisions.length; i++) {
if (activeCollisions[i] === TriggerSystem._instance?._cameraTriggerWrapper) continue
if (activeCollisions[i].trigger == null) continue

if (activeCollisions[i].trigger.onTriggerExit && wrapper.entity)
let activeCollisionHasTrigger = !(
activeCollisions[i] ===
TriggerSystem._instance?._cameraTriggerWrapper ||
activeCollisions[i].trigger == null
)

if (
activeCollisionHasTrigger &&
activeCollisions[i].trigger.onTriggerExit &&
wrapper.entity
)
(activeCollisions[i].trigger.onTriggerExit as (
entity: IEntity
) => void)(wrapper.entity)
Expand Down Expand Up @@ -239,8 +246,10 @@ export class TriggerSystem implements ISystem {
return (
t1.min.x <= t2.max.x &&
t1.max.x >= t2.min.x &&
t1.min.y <= t2.max.y && t1.max.y >= t2.min.y &&
t1.min.z <= t2.max.z && t1.max.z >= t2.min.z
t1.min.y <= t2.max.y &&
t1.max.y >= t2.min.y &&
t1.min.z <= t2.max.z &&
t1.max.z >= t2.min.z
)
}

Expand Down

0 comments on commit 981ef95

Please sign in to comment.