From f640d153558c36e405e1cd3c4a8cf024e2aae22a Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Mon, 23 Jan 2023 22:24:45 -0600 Subject: [PATCH] tailor: avoid bad key exception in std::map --- plugins/tailor.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 4e750cb3f..64c976424 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -249,7 +249,12 @@ private: for (auto w : worn) { auto ty = w->getType(); - auto o = itemTypeMap.at(ty); + auto oo = itemTypeMap.find(ty); + if (oo == itemTypeMap.end()) + { + continue; + } + const df::job_type o = oo->second; int size = world->raws.creatures.all[w->getMakerRace()]->adultsize; std::string description; @@ -330,9 +335,13 @@ private: } } - const df::job_type j = itemTypeMap.at(ty); - orders[std::make_tuple(j, sub, size)] += count; - DEBUG(cycle).print("tailor: %s times %d of size %d ordered\n", ENUM_KEY_STR(job_type, j).c_str(), count, size); + auto jj = itemTypeMap.find(ty); + if (jj != itemTypeMap.end()) + { + const df::job_type j = jj->second; + orders[std::make_tuple(j, sub, size)] += count; + DEBUG(cycle).print("tailor: %s times %d of size %d ordered\n", ENUM_KEY_STR(job_type, j).c_str(), count, size); + } } }