From 6ca28fb9c1d2700cacd8af15d555df8d32e8871b Mon Sep 17 00:00:00 2001 From: Arkadii Hlushchevskyi Date: Wed, 31 Jul 2024 21:57:42 +0300 Subject: [PATCH] Fixed a possible crash caused by missing ActorBase. --- SPID/src/OutfitManager.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SPID/src/OutfitManager.cpp b/SPID/src/OutfitManager.cpp index cfdca32..09f32e2 100644 --- a/SPID/src/OutfitManager.cpp +++ b/SPID/src/OutfitManager.cpp @@ -150,7 +150,12 @@ namespace Outfits } auto* npc = actor->GetActorBase(); - auto defaultOutfit = npc->defaultOutfit; + + if (!npc) { + return ReplacementResult::Skipped; + } + + auto defaultOutfit = npc->defaultOutfit; if (auto existing = replacements.find(actor->formID); existing != replacements.end()) { // we already have tracked replacement if (outfit == defaultOutfit && outfit == existing->second.distributed) { // if the outfit we are trying to set is already the default one and we have a replacement for it, then we confirm that it was set. @@ -219,9 +224,9 @@ namespace Outfits for (const auto& it : loadedReplacements) { const auto& actor = it.first; const auto& replacement = it.second; - if (auto newIt = newReplacements.find(actor->formID); newIt != newReplacements.end()) { // If we have some new replacement for this actor - newIt->second.original = replacement.original; // we want to forward original outfit from the previous replacement to the new one. (so that a chain of outfits like this A->B->C becomes A->C and we'll be able to revert to the very first outfit) - } else if (replacement.distributed == actor->GetActorBase()->defaultOutfit) { // If there is no new replacement, and an actor is currently wearing the same outfit that was distributed to them last time, we want to revert whatever outfit was in previous replacement + if (auto newIt = newReplacements.find(actor->formID); newIt != newReplacements.end()) { // If we have some new replacement for this actor + newIt->second.original = replacement.original; // we want to forward original outfit from the previous replacement to the new one. (so that a chain of outfits like this A->B->C becomes A->C and we'll be able to revert to the very first outfit) + } else if (auto npc = actor->GetActorBase(); npc && replacement.distributed == npc->defaultOutfit) { // If there is no new replacement, and an actor is currently wearing the same outfit that was distributed to them last time, we want to revert whatever outfit was in previous replacement #ifndef NDEBUG logger::info("\tReverting Outfit Replacement for {}", *actor); logger::info("\t\t{:R}", replacement);