From ec48445925c9bf656934887a1f557e3429aceb7f Mon Sep 17 00:00:00 2001
From: David Gilbert <gilbert@vr.rwth-aachen.de>
Date: Sat, 29 Mar 2025 11:57:05 +0100
Subject: [PATCH] hotfix(interaction): fixes crash that can happen when a
 previously grabbed item gets destroyed

---
 .../Interaction/Interactors/DirectInteractionComponent.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp b/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp
index 18e51581..f759b37b 100644
--- a/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp
+++ b/Source/RWTHVRToolkit/Private/Interaction/Interactors/DirectInteractionComponent.cpp
@@ -70,6 +70,13 @@ void UDirectInteractionComponent::TickComponent(float DeltaTime, ELevelTick Tick
 	// Call hover end events on all components that were previously in range, but not anymore
 	for (UInteractableComponent* PrevInteractableComp : PreviousInteractableComponentsInRange)
 	{
+		// It can happen that a previous component was destroyed
+		if (!PrevInteractableComp || !PrevInteractableComp->IsValidLowLevel())
+		{
+			ComponentsToRemove.Add(PrevInteractableComp); // might have to use indices here
+			continue;
+		}
+		
 		if (!CurrentInteractableCompsInRange.Contains(PrevInteractableComp))
 		{
 			ComponentsToRemove.AddUnique(PrevInteractableComp);
-- 
GitLab