From 52520e65c5d7e4d91dcf39214a0a04921246d349 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 31 Jul 2019 11:01:41 +0300
Subject: [PATCH] Fix for texture object destroyed bug

---
 components/common/cpp/include/ftl/cuda_common.hpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/components/common/cpp/include/ftl/cuda_common.hpp b/components/common/cpp/include/ftl/cuda_common.hpp
index 58e72ceb3..3f004d0c8 100644
--- a/components/common/cpp/include/ftl/cuda_common.hpp
+++ b/components/common/cpp/include/ftl/cuda_common.hpp
@@ -59,10 +59,12 @@ class TextureObject {
 	void download(cv::Mat &, cudaStream_t stream=0) const;
 	
 	__host__ void free() {
-		if (texobj_ != 0) cudaSafeCall( cudaDestroyTextureObject (texobj_) );
-		if (ptr_ && needsfree_) cudaFree(ptr_);
-		ptr_ = nullptr;
-		texobj_ = 0;
+		if (needsfree_) {
+			if (texobj_ != 0) cudaSafeCall( cudaDestroyTextureObject (texobj_) );
+			if (ptr_) cudaFree(ptr_);
+			ptr_ = nullptr;
+			texobj_ = 0;
+		}
 	}
 	
 	private:
-- 
GitLab