Fix MoveInteractable input handling race condition

This commit is contained in:
Oleg Petruny 2024-10-11 12:08:09 +02:00 committed by Oleg Petruny
parent 5a562a42ea
commit c869f82fc0
24 changed files with 7 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 KiB

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 128 B

View File

@ -97,6 +97,7 @@ void UMoveInteractableModificator::Unbind_Implementation()
void UMoveInteractableModificator::TurnOnHolding() void UMoveInteractableModificator::TurnOnHolding()
{ {
FScopeLock lock1(&critical);
holding = true; holding = true;
ProcessState(); ProcessState();
distance = (player->GetCameraLocation() - actor->GetActorLocation()).Length(); distance = (player->GetCameraLocation() - actor->GetActorLocation()).Length();
@ -105,6 +106,7 @@ void UMoveInteractableModificator::TurnOnHolding()
} }
void UMoveInteractableModificator::TurnOffHolding() void UMoveInteractableModificator::TurnOffHolding()
{ {
FScopeLock lock1(&critical);
holding = false; holding = false;
ProcessState(); ProcessState();
AMainGameModeBase::GetWidgetsManager()->AnimateInteractionHint(this, 0, EInputAnimatedWidgetAnimation::Unhold); AMainGameModeBase::GetWidgetsManager()->AnimateInteractionHint(this, 0, EInputAnimatedWidgetAnimation::Unhold);
@ -112,6 +114,7 @@ void UMoveInteractableModificator::TurnOffHolding()
void UMoveInteractableModificator::TurnOnRotating() void UMoveInteractableModificator::TurnOnRotating()
{ {
FScopeLock lock1(&critical);
rotating = true; rotating = true;
player->LockPlayer({ .camera = true }); player->LockPlayer({ .camera = true });
ProcessState(); ProcessState();
@ -120,6 +123,7 @@ void UMoveInteractableModificator::TurnOnRotating()
} }
void UMoveInteractableModificator::TurnOffRotating() void UMoveInteractableModificator::TurnOffRotating()
{ {
FScopeLock lock1(&critical);
rotating = false; rotating = false;
player->UnlockPlayer({ .camera = true }); player->UnlockPlayer({ .camera = true });
ProcessState(); ProcessState();
@ -130,7 +134,8 @@ void UMoveInteractableModificator::ProcessState()
{ {
if(holding || rotating) if(holding || rotating)
{ {
actor->activationLockers.Add(this); if(!actor->activationLockers.Contains(this))
actor->activationLockers.Add(this);
} }
else else
{ {

View File

@ -58,4 +58,5 @@ private:
bool rotating = false; bool rotating = false;
class AInteractable* actor = nullptr; class AInteractable* actor = nullptr;
class APlayerBase* player = nullptr; class APlayerBase* player = nullptr;
FCriticalSection critical;
}; };