Skip to content

Commit 20b0897

Browse files
committed
entities: fix Destroy() not being called in some cases (#139)
when a player disconnects and is replaced by a bot, the bot may have the same entity-ID as the player. also the player's entity may not have been destroyed, since the PVS-leave update was never sent. for this case we need to make sure old entities are destoryed before calling ReadEnterPVS().
1 parent cd04f93 commit 20b0897

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

entities.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func (p *Parser) handlePacketEntities(pe *msg.CSVCMsg_PacketEntities) {
3333
r.ReadBit()
3434
} else if r.ReadBit() {
3535
// Enter PVS
36+
if existing := p.gameState.entities[currentEntity]; existing != nil {
37+
// Sometimes entities don't get destroyed when they should be
38+
// For instance when a player is replaced by a BOT
39+
existing.Destroy()
40+
}
3641
p.gameState.entities[currentEntity] = p.stParser.ReadEnterPVS(r, currentEntity)
3742
} else {
3843
// Delta Update

0 commit comments

Comments
 (0)