From 8e9b45ddc0ffe81655890877983d0635c9aaf2d7 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Thu, 15 Jun 2023 19:07:59 +0200 Subject: [PATCH] fix the motion source options crashes --- .../Components/SGWristTrackerComponent.cpp | 30 ++++++++++++----- .../Components/SGWristTrackerComponent.h | 33 ++++++++++--------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp index 364b68b0..cd09d5e4 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp @@ -84,6 +84,7 @@ struct USGWristTrackerComponent::FImpl bool UninitializeBackend() const; bool CheckGlove() const; + void UpdateMotionSource() const; void UpdateWristTrackingData() const; void DrawDebugGizmo(); }; @@ -125,12 +126,18 @@ USGWristTrackerComponent::USGWristTrackerComponent(const FObjectInitializer& Obj ) ); + bRight = true; + bBackendInitialized = false; Glove = nullptr; WristLocation = FVector::ZeroVector; WristRotation = FRotator::ZeroRotator; +} - SetRight(true); +void USGWristTrackerComponent::SetRight(const bool bInRight) +{ + bRight = bInRight; + Pimpl->UpdateMotionSource(); } const FSGWristTrackingSettings& USGWristTrackerComponent::GetWristTrackingSettings() const @@ -158,13 +165,6 @@ void USGWristTrackerComponent::SetWristTrackingSettings(const FSGWristTrackingSe WristTrackingSettings = InWristTrackingSettings; } -void USGWristTrackerComponent::SetRight(const bool bRight) -{ - SetTrackingSource(bRight - ? GetWristTrackingSettings().LeftHandMotionSource - : GetWristTrackingSettings().RightHandMotionSource); -} - #if WITH_EDITOR void USGWristTrackerComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) { @@ -188,6 +188,8 @@ void USGWristTrackerComponent::InitializeComponent() { (void) Pimpl->CheckGlove(); } + + Pimpl->UpdateMotionSource(); } void USGWristTrackerComponent::UninitializeComponent() @@ -205,6 +207,8 @@ void USGWristTrackerComponent::BeginPlay() { (void) Pimpl->CheckGlove(); } + + Pimpl->UpdateMotionSource(); } void USGWristTrackerComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) @@ -378,6 +382,16 @@ bool USGWristTrackerComponent::FImpl::CheckGlove() const return bFoundGlove; } +void USGWristTrackerComponent::FImpl::UpdateMotionSource() const +{ + if (GEngine) + { + Owner->SetTrackingSource(Owner->IsRight() + ? Owner->GetWristTrackingSettings().LeftHandMotionSource + : Owner->GetWristTrackingSettings().RightHandMotionSource); + } +} + void USGWristTrackerComponent::FImpl::UpdateWristTrackingData() const { ensureAlwaysMsgf(Owner->Glove, TEXT("Invalid Glove!")); diff --git a/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h b/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h index 3b6768bc..6ecc4a56 100644 --- a/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h +++ b/Source/SenseGlove/Public/SenseGlove/Components/SGWristTrackerComponent.h @@ -94,17 +94,20 @@ private: FImplDeleter PimplDeleter; private: + UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false")) + uint8 bRight : 1; + /** * Determines whether to override the plugin's wrist tracking settings or not. */ - UPROPERTY(Config, EditAnywhere, Category = "SenseGlove") + UPROPERTY(EditAnywhere, Category = "SenseGlove", meta=(AllowPrivateAccess="false")) uint8 bOverridePluginWristTrackingSettings : 1; /** * Overrides the plugin's wrist tracking settings. */ - UPROPERTY(Config, EditAnywhere, Category = "SenseGlove", - meta=(EditCondition="bOverridePluginWristTrackingSettings", EditConditionHides)) + UPROPERTY(EditAnywhere, Category = "SenseGlove", + meta=(AllowPrivateAccess="false", EditCondition="bOverridePluginWristTrackingSettings", EditConditionHides)) FSGWristTrackingSettings WristTrackingSettings; private: @@ -121,6 +124,18 @@ private: FRotator WristRotation; public: + FORCEINLINE bool IsLeft() const + { + return !IsRight(); + } + + FORCEINLINE bool IsRight() const + { + return !!bRight; + } + + void SetRight(const bool bInRight); + FORCEINLINE bool OverridesPluginWristTrackingSettings() const { return !!bOverridePluginWristTrackingSettings; @@ -134,18 +149,6 @@ public: const FSGWristTrackingSettings& GetWristTrackingSettings() const; void SetWristTrackingSettings(const FSGWristTrackingSettings& InWristTrackingSettings); - FORCEINLINE bool IsLeft() const - { - return GetTrackingSource() == GetWristTrackingSettings().LeftHandMotionSource; - } - - FORCEINLINE bool IsRight() const - { - return GetTrackingSource() == GetWristTrackingSettings().RightHandMotionSource; - } - - void SetRight(const bool bRight); - FORCEINLINE const FVector& GetWristLocation() const { return WristLocation;