From ce3c63970a93b42f3e36aae95bce7085cace081a Mon Sep 17 00:00:00 2001
From: dgilbert <gilbert@vr.rwth-aachen.de>
Date: Wed, 4 Sep 2019 10:11:37 +0200
Subject: [PATCH] I'm an idiot

---
 Source/OptiX/Private/OptiXLaserActor.cpp  | 40 +++++++++++------------
 Source/OptiX/Public/OptiXContextManager.h | 18 ++++++++++
 Source/OptiX/Public/OptiXLaserActor.h     |  2 +-
 3 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/Source/OptiX/Private/OptiXLaserActor.cpp b/Source/OptiX/Private/OptiXLaserActor.cpp
index 93b7d4b..4780c71 100644
--- a/Source/OptiX/Private/OptiXLaserActor.cpp
+++ b/Source/OptiX/Private/OptiXLaserActor.cpp
@@ -16,7 +16,7 @@ AOptiXLaserActor::AOptiXLaserActor(const FObjectInitializer& ObjectInitializer)
 {
 	UE_LOG(LogTemp, Display, TEXT("OptiX Laser Actor Constructor"));
 
-	PrimaryActorTick.bCanEverTick = false;
+	PrimaryActorTick.bCanEverTick = true;
 
 	static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/OptiX/Laser/laser3.laser3'"));
 	UStaticMesh* Asset = MeshAsset.Object;
@@ -95,25 +95,25 @@ void AOptiXLaserActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
 	UE_LOG(LogTemp, Warning, TEXT("OptiX Laser Actor EndPlay")); 
 }
 
-void AOptiXLaserActor::Tick(float DeltaTime)
-{
-	// We don't need to trace each tick, but only if either the optix scene changed, or the laser position moved. 
-	Super::Tick(DeltaTime);
-
-	//LineInstancedStaticMeshComponent->UpdateLines();
-
-	//if (bLaserTraceEnabled)
-	//{		
-	//	// Check if there's anything in the queue
-
-	//	if (!FOptiXModule::Get().GetOptiXContextManager()->LaserIntersectionQueue.IsEmpty())
-	//	{
-	//		DisplayLines();
-	//	}
-	//}
-
-
-}
+//void AOptiXLaserActor::Tick(float DeltaTime)
+//{
+//	// We don't need to trace each tick, but only if either the optix scene changed, or the laser position moved. 
+//	Super::Tick(DeltaTime);
+//
+//	//LineInstancedStaticMeshComponent->UpdateLines();
+//
+//	//if (bLaserTraceEnabled)
+//	//{		
+//	//	// Check if there's anything in the queue
+//
+//	//	if (!FOptiXModule::Get().GetOptiXContextManager()->LaserIntersectionQueue.IsEmpty())
+//	//	{
+//	//		DisplayLines();
+//	//	}
+//	//}
+//
+//
+//}
 
 //void AOptiXLaserActor::InitInstancedMeshData()
 //{
diff --git a/Source/OptiX/Public/OptiXContextManager.h b/Source/OptiX/Public/OptiXContextManager.h
index 2b0b241..5292332 100644
--- a/Source/OptiX/Public/OptiXContextManager.h
+++ b/Source/OptiX/Public/OptiXContextManager.h
@@ -63,9 +63,12 @@ public:
 			cudaGraphicsUnregisterResource(CudaResourceDepthRight);
 			cudaGraphicsUnregisterResource(CudaResourceColorLeft);
 			cudaGraphicsUnregisterResource(CudaResourceColorRight);
+			cudaGraphicsUnregisterResource(CudaResourceIntersections);
+
 			PrintLastCudaError("cudaGraphicsUnregisterResource");
 			cudaFree(CudaLinearMemoryDepth);
 			cudaFree(CudaLinearMemoryColor);
+			cudaFree(CudaLinearMemoryIntersections);
 			PrintLastCudaError("cudaFree");
 		}
 
@@ -79,6 +82,16 @@ public:
 		ProgramToDeleteQueue.Empty();
 		TextureSamplersToDeleteQueue.Empty();
 		TransformsToDeleteQueue.Empty();
+
+		GroupChildrenToRemoveQueue.Empty();
+		GeometryGroupChildrenToRemoveQueue.Empty();
+
+		ComponentsToInitializeQueue.Empty();
+		ComponentsToUpdateQueue.Empty();
+		CubemapComponentsToUpdateQueue.Empty();
+
+		LaserActor.Reset();
+		CameraActor.Reset();
 	}
 
 	// ISceneViewExtension interface start, called by the render thread:
@@ -526,11 +539,16 @@ private:
 		DepthTexture.Reset();
 		OutputTexture2.Reset();
 		DepthTexture2.Reset();
+		LaserIntersectionTexture.Reset();
 
 		DynamicMaterial.Reset();
 		RegularMaterial.Reset();
 		VRMaterial.Reset();
+		LaserMaterial.Reset();
+
+		LaserMaterialDynamic.Reset();		
 
+		LaserActor.Reset();
 
 		TopObject.Reset();
 		TopAcceleration.Reset();
diff --git a/Source/OptiX/Public/OptiXLaserActor.h b/Source/OptiX/Public/OptiXLaserActor.h
index 1523428..06902cd 100644
--- a/Source/OptiX/Public/OptiXLaserActor.h
+++ b/Source/OptiX/Public/OptiXLaserActor.h
@@ -32,7 +32,7 @@ public:
 
 	virtual void BeginPlay() override;
 	virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
-	virtual void Tick(float DeltaTime) override;
+	//virtual void Tick(float DeltaTime) override;
 
 	//UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXActor")
 	//void DisplayLines();	
-- 
GitLab