From 714fb032e9ec26e7bc4fab6f074a0c69c4221e76 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Wed, 28 Sep 2022 21:03:05 -0500 Subject: [PATCH] [Crash] Fix spawn race condition shown by #repop (#2455) * Troubleshooting * Debugging * Debugging * Debugging * Debugging * Remove debug line * Revert back to GetRawNPCTypeName --- zone/entity.cpp | 8 +++++--- zone/gm_commands/repop.cpp | 5 ++--- zone/spawn2.cpp | 5 +++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/zone/entity.cpp b/zone/entity.cpp index 5be724eb4..091c6101c 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -4257,10 +4257,12 @@ bool EntityList::LimitCheckName(const char *npc_name) { auto it = npc_list.begin(); while (it != npc_list.end()) { - NPC* npc = it->second; - if (npc) - if (strcasecmp(npc_name, npc->GetRawNPCTypeName()) == 0) + NPC *npc = it->second; + if (npc) { + if (strcasecmp(npc_name, npc->GetRawNPCTypeName()) == 0) { return false; + } + } ++it; } return true; diff --git a/zone/gm_commands/repop.cpp b/zone/gm_commands/repop.cpp index e1d4d6dbe..aa98b105d 100755 --- a/zone/gm_commands/repop.cpp +++ b/zone/gm_commands/repop.cpp @@ -4,9 +4,9 @@ void command_repop(Client *c, const Seperator *sep) { int arguments = sep->argnum; if (!arguments) { + entity_list.ClearAreas(); c->Message(Chat::White, "Zone depopped, repopping now."); zone->Repop(); - zone->spawn2_timer.Trigger(); return; } @@ -15,11 +15,10 @@ void command_repop(Client *c, const Seperator *sep) if (is_force) { zone->ClearSpawnTimers(); c->Message(Chat::White, "Zone depopped, forcefully repopping now."); - } else { + } else { c->Message(Chat::White, "Zone depopped, repopping now."); } zone->Repop(); - zone->spawn2_timer.Trigger(); } diff --git a/zone/spawn2.cpp b/zone/spawn2.cpp index c478db1e4..3aed89a63 100644 --- a/zone/spawn2.cpp +++ b/zone/spawn2.cpp @@ -205,6 +205,11 @@ bool Spawn2::Process() { return (true); } + if (tmp->npc_id == 0) { + LogError("NPC type did not load for npc_id [{}]", npcid); + return true; + } + if (tmp->unique_spawn_by_name) { if (!entity_list.LimitCheckName(tmp->name)) { LogSpawns("Spawn2 [{}]: Spawn group [{}] yeilded NPC type [{}], which is unique and one already exists", spawn2_id, spawngroup_id_, npcid);