From cef8a61d9cb0b915feed2346ea07af5871ed82ec Mon Sep 17 00:00:00 2001 From: Ilan Schemoul Date: Wed, 12 Mar 2025 22:17:11 +0100 Subject: [PATCH] fix: crash when spectating (#232) Nuke icon patch added a crash when spectating game (myPlayer is NULL) --- src/client/graphics/layers/NameLayer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/graphics/layers/NameLayer.ts b/src/client/graphics/layers/NameLayer.ts index d5ba46fa0..2b4f56fc3 100644 --- a/src/client/graphics/layers/NameLayer.ts +++ b/src/client/graphics/layers/NameLayer.ts @@ -418,7 +418,7 @@ export class NameLayer implements Layer { const nukesSentByOtherPlayer = this.game.units().filter((unit) => { const isSendingNuke = render.player.id() == unit.owner().id(); - const notMyPlayer = unit.owner().id() != myPlayer.id(); + const notMyPlayer = !myPlayer || unit.owner().id() != myPlayer.id(); return ( nukeTypes.includes(unit.type()) && isSendingNuke && @@ -429,7 +429,7 @@ export class NameLayer implements Layer { const isMyPlayerTarget = nukesSentByOtherPlayer.find((unit) => { const detonationDst = unit.detonationDst(); const targetId = this.game.owner(detonationDst).id(); - return targetId == this.myPlayer.id(); + return myPlayer && targetId == this.myPlayer.id(); }); const existingNuke = iconsDiv.querySelector( '[data-icon="nuke"]', @@ -449,7 +449,7 @@ export class NameLayer implements Layer { ) { existingNuke.src = this.nukeWhiteIconImage.src; } - } else if (myPlayer && nukesSentByOtherPlayer.length > 0) { + } else if (nukesSentByOtherPlayer.length > 0) { if (!existingNuke) { const icon = isMyPlayerTarget ? this.nukeRedIconImage.src