fix lambda crashes and ensure logic bugs

This commit is contained in:
Mamadou Babaei
2023-05-19 18:14:40 +02:00
parent 4b8bae5bb7
commit da1ad71b8b
4 changed files with 19 additions and 9 deletions
@@ -68,7 +68,7 @@ struct USGGrabComponent::FImpl
USGGrabComponent* USGGrabComponent::GetGrabComponent(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return nullptr;
}
@@ -80,7 +80,7 @@ USGGrabComponent* USGGrabComponent::GetGrabComponent(const AActor* Actor)
bool USGGrabComponent::IsGrabbable(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return false;
}
@@ -68,7 +68,7 @@ struct USGTouchComponent::FImpl
USGTouchComponent* USGTouchComponent::GetTouchComponent(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return nullptr;
}
@@ -80,7 +80,7 @@ USGTouchComponent* USGTouchComponent::GetTouchComponent(const AActor* Actor)
bool USGTouchComponent::IsTouchable(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return false;
}
@@ -1216,7 +1216,7 @@ bool ASGPawn::IsGrabbing(const USGVirtualHandComponent* Hand, AActor*& OutActor)
void ASGPawn::GrabLeft(AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return;
}
@@ -1240,7 +1240,7 @@ void ASGPawn::GrabLeft(AActor* Actor)
void ASGPawn::GrabRight(AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
if (!ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return;
}
@@ -186,17 +186,22 @@ void ASGPlayerController::BeginPlay()
Super::BeginPlay();
ASGPawn* SGPawn = Cast<ASGPawn>(GetPawn());
if (ensureAlwaysMsgf(IsValid(SGPawn), TEXT("%s"), TEXT("ERROR: invalid SenseGlove pawn!")))
if (!ensureAlwaysMsgf(IsValid(SGPawn), TEXT("%s"), TEXT("ERROR: invalid SenseGlove pawn!")))
{
return;
}
SGPawn->OnGrabStateUpdated().AddWeakLambda(
this, [&](
this, [=](
const USGVirtualHandComponent* Hand,
AActor* ActorThumbCanGrab, const AActor* ActorIndexCanGrab,
const AActor* ActorMiddleCanGrab) -> void
{
if (!IsValid(SGPawn))
{
return;
}
if (!IsValid(Hand))
{
return;
@@ -220,11 +225,16 @@ void ASGPlayerController::BeginPlay()
});
SGPawn->OnTouchStateUpdated().AddWeakLambda(
this, [&](
this, [=](
const USGVirtualHandComponent* Hand,
const AActor* ActorThumbTouching, const AActor* ActorIndexTouching, const AActor* ActorMiddleTouching,
const AActor* ActorRingTouching, const AActor* ActorPinkyTouching) -> void
{
if (!IsValid(SGPawn))
{
return;
}
if (!IsValid(Hand))
{
return;