Skip to content

Commit 3428a13

Browse files
authored
Fix OptiX crash on Windows (#253)
* Fix OptiX cleanup crash on Windows * Enable RclcppInitializeAndShutDownProperly test on Windows * Fix typo
1 parent 05dea74 commit 3428a13

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Optix.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ static CUcontext getCurrentDeviceContext()
5252
const char* error = nullptr;
5353
CUresult status;
5454

55-
cudaFree(nullptr); // Force CUDA runtime initialization
56-
5755
CUdevice device;
5856
status = cuDeviceGet(&device, 0);
5957
if (status != CUDA_SUCCESS) {
@@ -156,6 +154,13 @@ Optix::Optix()
156154

157155
Optix::~Optix()
158156
{
157+
// On Windows, when program is terminated, CUDA gets unloaded before OptiX.
158+
// If that happens, OptiX fails to de-initialize and crashes program with an error 0xc0000409 STATUS_STACK_BUFFER_OVERRUN
159+
// Therefore, if CUDA is unloaded, we give up de-initializing OptiX, hoping that CUDA de-initialization did it.
160+
if (cudaFree(nullptr) == cudaErrorCudartUnloading) {
161+
return;
162+
}
163+
159164
if (pipeline) {
160165
optixPipelineDestroy(pipeline);
161166
}

test/src/externalLibraryTest.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
class ExternalLibraryTest : public RGLTest
1010
{};
1111

12-
// TODO (msz-rai): Make it work on Windows.
13-
// Currently, there is a bug when destroying Optix on Windows which causes non-zero exit code.
14-
#if RGL_BUILD_ROS2_EXTENSION && __GNUC__
12+
#if RGL_BUILD_ROS2_EXTENSION
1513
/**
1614
* rclcpp library (part of the ROS2 extension) depends on spdlog library.
1715
* RGL also uses spdlog for logging purposes.

0 commit comments

Comments
 (0)