From 9a21b456ae0d27fefe613b4ccea99cb574753c7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <tmueller@nvidia.com>
Date: Mon, 9 Jan 2023 09:53:32 +0100
Subject: [PATCH] Fix crash with multiple GPUs, having the screen not connected
 to the first

---
 .editorconfig  | 1 -
 src/testbed.cu | 6 +++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 2685994..cfe46c9 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -13,4 +13,3 @@ trim_trailing_whitespace = false
 [*.yml]
 indent_style = spaces
 indent_size = 2
-
diff --git a/src/testbed.cu b/src/testbed.cu
index 4ba985c..c50d269 100644
--- a/src/testbed.cu
+++ b/src/testbed.cu
@@ -2902,7 +2902,7 @@ Testbed::Testbed(ETestbedMode mode) {
 			int gl_device = -1;
 			unsigned int device_count = 0;
 			if (cudaGLGetDevices(&device_count, &gl_device, 1, cudaGLDeviceListAll) == cudaSuccess) {
-				if (device_count > 0 && gl_device != -1) {
+				if (device_count > 0 && gl_device >= 0) {
 					set_cuda_device(gl_device);
 				}
 			}
@@ -2912,6 +2912,10 @@ Testbed::Testbed(ETestbedMode mode) {
 
 		glfwTerminate();
 	}
+
+	// Reset our stream, which was allocated on the originally active device,
+	// to make sure it corresponds to the now active device.
+	m_stream = {};
 #endif
 
 	int active_device = cuda_device();
-- 
GitLab