[Crash] Fix spawn race condition shown by #repop (#2455)

* Troubleshooting

* Debugging

* Debugging

* Debugging

* Debugging

* Remove debug line

* Revert back to GetRawNPCTypeName
This commit is contained in:
Chris Miles 2022-09-28 21:03:05 -05:00 committed by GitHub
parent 74dfc1ae3c
commit 714fb032e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -4257,10 +4257,12 @@ bool EntityList::LimitCheckName(const char *npc_name)
{ {
auto it = npc_list.begin(); auto it = npc_list.begin();
while (it != npc_list.end()) { while (it != npc_list.end()) {
NPC* npc = it->second; NPC *npc = it->second;
if (npc) if (npc) {
if (strcasecmp(npc_name, npc->GetRawNPCTypeName()) == 0) if (strcasecmp(npc_name, npc->GetRawNPCTypeName()) == 0) {
return false; return false;
}
}
++it; ++it;
} }
return true; return true;

View File

@ -4,9 +4,9 @@ void command_repop(Client *c, const Seperator *sep)
{ {
int arguments = sep->argnum; int arguments = sep->argnum;
if (!arguments) { if (!arguments) {
entity_list.ClearAreas();
c->Message(Chat::White, "Zone depopped, repopping now."); c->Message(Chat::White, "Zone depopped, repopping now.");
zone->Repop(); zone->Repop();
zone->spawn2_timer.Trigger();
return; return;
} }
@ -15,11 +15,10 @@ void command_repop(Client *c, const Seperator *sep)
if (is_force) { if (is_force) {
zone->ClearSpawnTimers(); zone->ClearSpawnTimers();
c->Message(Chat::White, "Zone depopped, forcefully repopping now."); c->Message(Chat::White, "Zone depopped, forcefully repopping now.");
} else { } else {
c->Message(Chat::White, "Zone depopped, repopping now."); c->Message(Chat::White, "Zone depopped, repopping now.");
} }
zone->Repop(); zone->Repop();
zone->spawn2_timer.Trigger();
} }

View File

@ -205,6 +205,11 @@ bool Spawn2::Process() {
return (true); 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 (tmp->unique_spawn_by_name) {
if (!entity_list.LimitCheckName(tmp->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); LogSpawns("Spawn2 [{}]: Spawn group [{}] yeilded NPC type [{}], which is unique and one already exists", spawn2_id, spawngroup_id_, npcid);