Fix player count showing 0 after returning from a race

When exiting a race, LegoRace::Create stashes the UserActor and sets
it to NULL. The destructor restores it, but runs later than
OnWorldEnabled, so NotifyPlayerCountChanged sees a NULL UserActor and
doesn't count the local player. Fall back to GameState::GetActorId()
which is restored earlier (in LegoRace::Enable(FALSE)).
This commit is contained in:
Christian Semmler 2026-03-07 21:57:20 -08:00
parent e0a1ac781f
commit dd56e6c686
No known key found for this signature in database
GPG Key ID: 086DAA1360BEEE5C

View File

@ -641,12 +641,18 @@ void NetworkManager::NotifyPlayerCountChanged()
if (m_inIsleWorld) {
count = 0;
// Only count the local player if they have a valid actor
// (players who enter Isle without selecting a save have no actor).
// Only count the local player if they have a valid actor.
// UserActor() can be temporarily NULL during world transitions
// (e.g. returning from a race, where LegoRace stashes the actor
// and only restores it in its destructor). Fall back to the
// GameState actorId which is restored earlier.
LegoPathActor* userActor = UserActor();
if (userActor && IsValidActorId(static_cast<LegoActor*>(userActor)->GetActorId())) {
count = 1;
}
else if (IsValidActorId(GameState()->GetActorId())) {
count = 1;
}
for (auto& [peerId, player] : m_remotePlayers) {
if (player->GetWorldId() == (int8_t) LegoOmni::e_act1) {