Skip to content

Commit

Permalink
without throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
nic11 committed Jan 15, 2025
1 parent 5a977ac commit dc217c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion antigo/include/antigo/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OnstackContext
void AddLambdaWithOwned(std::function<std::string()> printerFunc);
[[nodiscard]] impl::ReferencedValueGuard AddLambdaWithRef(std::function<std::string()> printerFunc);

ResolvedContext Resolve() const;
[[nodiscard]] ResolvedContext Resolve() const;
void Orphan() const;

// XXX: move to some common headedr?
Expand Down
4 changes: 4 additions & 0 deletions skymp5-server/cpp/server_guest_lib/EvaluateTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ auto EvaluateTemplate(WorldState* worldState, uint32_t baseId,
detailedLog << "Variable npcData: baseTemplate=" << npcData.baseTemplate
<< ", templateDataFlags=" << npcData.templateDataFlags << "\n";

ctx.AddLambdaWithOwned([s = detailedLog.str()] {
return s;
});

try {
if (npcData.baseTemplate == 0) {
return callback(npcLookupResult, npcData);
Expand Down
13 changes: 11 additions & 2 deletions skymp5-server/cpp/server_guest_lib/MpObjectReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ std::vector<espm::CONT::ContainerObject> GetOutfitObjects(
auto result = npcLookupRes.ToGlobalId(npcData.defaultOutfitId);
if (result == 0) {
ctx.AddMessage("evaluated NPC template - outfitId is 0");
throw std::runtime_error("failed NPC template eval"); // this will make context log everything
ctx.Orphan();
}
return result;
});
Expand Down Expand Up @@ -1921,14 +1921,23 @@ void MpObjectReference::EnsureBaseContainerAdded(espm::Loader& espm)
return;
}

ctx.AddMessage("next: AsActor(), templateChain, lookupRes");
ctx.AddMessage("next: AsActor(), templateChain, lookupRes.rec");

auto actor = AsActor();
ctx.AddPtr(actor);
const std::vector<FormDesc> kEmptyTemplateChain;
const std::vector<FormDesc>& templateChain =
actor ? actor->GetTemplateChain() : kEmptyTemplateChain;
ctx.AddLambdaWithOwned([templateChain]{
std::string s = "[\n";
for (const auto& elt : templateChain) {
s += " " + elt.ToString() + "\n";
}
return s + "]";
});

auto lookupRes = espm.GetBrowser().LookupById(GetBaseId());
ctx.AddPtr(lookupRes.rec);

std::map<uint32_t, uint32_t> itemsToAdd, itemsToEquip;

Expand Down

0 comments on commit dc217c3

Please sign in to comment.