From 170ee2d66bc1e810b961ae1a51797262680b66f3 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 12 Apr 2024 06:56:04 +0200 Subject: [PATCH] only instantiate the connected glove once instead of recreating and destroying it every frame --- CHANGELOG.md | 1 + .../Components/SGVirtualHandComponent.cpp | 21 ++++++++++++------- .../Components/SGWristTrackerComponent.cpp | 19 +++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b35012..d388589b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fix a bug inside both SGVirtualHandComponent and SGWristTrackerComponent where the connected glove's UObject instance gets destroyed and re-instantiated every frame. With this fix now the glove instance will be created or destroyed only when a glove connects to or disconnects from the system. - Update the outdated Platform Support Matrix and its remarks section to reflect the latest status information. - Fix the wrong header file description sections for the header files inside SenseGloveKismet/Public/SGKismet/. diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp index 0ded475f..d5ecd945 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGVirtualHandComponent.cpp @@ -598,13 +598,18 @@ bool USGVirtualHandComponent::FImpl::CheckGlove() const } } - const bool bGloveWasPresent = IsValid(Owner->Glove); - const bool bFoundGlove = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove); - - if (!bFoundGlove && bGloveWasPresent) + bool bGloveConnected; + if (!IsValid(Owner->Glove) || !Owner->Glove->IsConnected()) { - SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove!"), - (Owner->IsRight() ? TEXT("right-handed") : TEXT("left-handed")))); + bGloveConnected = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove); + if (!bGloveConnected) + { + Owner->Glove = nullptr; + } + } + else + { + bGloveConnected = true; } const bool bIsEditor = IsEditor(); @@ -613,7 +618,7 @@ bool USGVirtualHandComponent::FImpl::CheckGlove() const const bool bIsVisible = Owner->IsVisible(); if (Owner->bHiddenInGameIfNoGloveDetected) { - if (bFoundGlove) + if (bGloveConnected) { if (!bIsVisible) { @@ -637,7 +642,7 @@ bool USGVirtualHandComponent::FImpl::CheckGlove() const } } - return bFoundGlove; + return bGloveConnected; } void USGVirtualHandComponent::FImpl::DrawDebugVirtualHand() const diff --git a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp index 8b384b83..37c991f2 100644 --- a/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp +++ b/Source/SenseGlove/Private/SenseGlove/Components/SGWristTrackerComponent.cpp @@ -251,21 +251,22 @@ bool USGWristTrackerComponent::FImpl::CheckGlove() const } } - const bool bGloveWasPresent = IsValid(Owner->Glove); - const bool bFoundGlove = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove); - - if (!bFoundGlove && bGloveWasPresent) + bool bGloveConnected; + if (!IsValid(Owner->Glove) || !Owner->Glove->IsConnected()) { - SGLOG_ERROR(FString::Printf(TEXT("Could not find a %s glove!"), - (Owner->IsRight() ? TEXT("right-handed") : TEXT("left-handed")))); + bGloveConnected = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove); + if (!bGloveConnected) + { + Owner->Glove = nullptr; + } } - - if (bFoundGlove) + else { + bGloveConnected = true; UpdateWristTrackingData(); } - return bFoundGlove; + return bGloveConnected; } void USGWristTrackerComponent::FImpl::UpdateMotionSource() const