Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(skymp5-server): debug crash #2213

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions skymp5-server/cpp/server_guest_lib/MpObjectReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <map>
#include <numeric>
#include <optional>
#include <stacktrace>

#include "OpenContainerMessage.h"
#include "TeleportMessage.h"
Expand Down Expand Up @@ -128,6 +129,13 @@ struct PrimitiveData
GeoProc::GeoPolygonProc polygonProc;
};

struct SetPropertyTrackingInfo
{
std::string propertyName;
nlohmann::json value;
std::stacktrace trace;
};

struct MpObjectReference::Impl
{
public:
Expand All @@ -137,6 +145,8 @@ struct MpObjectReference::Impl
AnimGraphHolder animGraphHolder;
std::optional<PrimitiveData> primitive;
bool teleportFlag = false;

std::unique_ptr<SetPropertyTrackingInfo> setPropertyTrackingInfo;
bool setPropertyCalled = false;
};

Expand Down Expand Up @@ -709,6 +719,13 @@ void MpObjectReference::SetProperty(const std::string& propertyName,
}
}
pImpl->setPropertyCalled = true;

if (GetFormId() == 0xE2218) {
setPropertyTrackingInfo.reset(new SetPropertyTrackingInfo);
setPropertyTrackingInfo->propertyName = propertyName;
setPropertyTrackingInfo->value = newValue;
setPropertyTrackingInfo->trace = std::stacktrace::current();
}
}

void MpObjectReference::SetTeleportFlag(bool value)
Expand Down Expand Up @@ -1129,8 +1146,35 @@ MpChangeForm MpObjectReference::GetChangeForm() const
void MpObjectReference::ApplyChangeForm(const MpChangeForm& changeForm)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider resetting pImpl->setPropertyTrackingInfo after logging in ApplyChangeForm to avoid incorrect logging in subsequent calls.

{
if (pImpl->setPropertyCalled) {
GetParent()->logger->critical("ApplyChangeForm called after SetProperty");
std::terminate();
spdlog::critical(
"MpObjectReference::ApplyChangeForm {:x} - called after SetProperty",
GetFormId());

auto& setPropertyTrackingInfo = pImpl->setPropertyTrackingInfo;

spdlog::critical(
"setPropertyTrackingInfo: propertyName = {}, value = {}",
setPropertyTrackingInfo ? setPropertyTrackingInfo->propertyName
: std::string("<No property name>"),
setPropertyTrackingInfo ? setPropertyTrackingInfo->value.dump()
: std::string("<No value>"));

std::stringstream ss;

if (setPropertyTrackingInfo) {
auto trace = setPropertyTrackingInfo->trace;
for (std::size_t i = 0; i < trace.size(); ++i) {
ss << "#" << i << ": " << trace[i] << '\n';
}
} else {
ss << "<No trace available>";
}

spdlog::critical("setPropertyTrackingInfo: trace = {}", ss.str());

pImpl->setPropertyTrackingInfo.reset();

// std::terminate();
}

blockSaving = true;
Expand Down
Loading