Skip to content

Commit 4103310

Browse files
authored
Fix crash in OnNotifyRelinquishControl (#732)
The call to retrieve the Actor:: can fail, so avoid the crash.
1 parent f4f2249 commit 4103310

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Code/client/Services/Generic/CharacterService.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ void CharacterService::OnNotifyRelinquishControl(const NotifyRelinquishControl&
975975
std::optional<uint32_t> serverIdRes = Utils::GetServerId(entity);
976976
if (!serverIdRes.has_value())
977977
{
978-
spdlog::error("{}: failed to find server id", __FUNCTION__);
978+
spdlog::error(__FUNCTION__ ": failed to find server id for entity");
979979
continue;
980980
}
981981

@@ -992,12 +992,19 @@ void CharacterService::OnNotifyRelinquishControl(const NotifyRelinquishControl&
992992
}
993993

994994
Actor* pActor = Cast<Actor>(TESForm::GetById(formIdComponent.Id));
995+
if (!pActor)
996+
{
997+
// Probably left the room and/or temporary.
998+
spdlog::info(__FUNCTION__ ": no local Actor for serverId {:X} to relinquish", serverId);
999+
continue;
1000+
}
1001+
9951002
pActor->GetExtension()->SetRemote(true);
9961003

9971004
InterpolationSystem::Setup(m_world, entity);
9981005
AnimationSystem::Setup(m_world, entity);
9991006

1000-
spdlog::info("Relinquished control of actor {:X} with server id {:X}", pActor->formID, acMessage.ServerId);
1007+
spdlog::info(__FUNCTION__ ": relinquished control of actor {:X} with server id {:X}", pActor->formID, acMessage.ServerId);
10011008

10021009
return;
10031010
}

0 commit comments

Comments
 (0)