From 3de2beab2b7b7ce884d963d8e031f02085c743be Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Tue, 9 May 2023 12:22:11 +0200 Subject: [PATCH] fix lambda crashes and ensure logic bugs --- .../SenseGlove/Components/SGGrabComponent.cpp | 4 ++-- .../SenseGlove/Components/SGTouchComponent.cpp | 4 ++-- .../Private/SenseGlove/GameFramework/SGPawn.cpp | 4 ++-- .../GameFramework/SGPlayerController.cpp | 16 +++++++++++++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp index 375f5f39..aa1e2135 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGGrabComponent.cpp @@ -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; } diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp index 086694c0..cea495b1 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGTouchComponent.cpp @@ -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; } diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp index 1cfd01c3..5cb60523 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPawn.cpp @@ -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; } diff --git a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp index 663e396d..4796ad78 100644 --- a/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp +++ b/Source/SenseGlove/Private/SenseGlove/GameFramework/SGPlayerController.cpp @@ -186,17 +186,22 @@ void ASGPlayerController::BeginPlay() Super::BeginPlay(); ASGPawn* SGPawn = Cast(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;