Skip to content

Commit 4693c83

Browse files
committed
GLResource.unmap(): tolerate shut-down OpenGL context
1 parent 52cf523 commit 4693c83

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/gl_interop.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void jit_unregister_cuda_resource(void *cuda_resource) {
3838
ThreadState *ts = thread_state(JitBackend::CUDA);
3939
scoped_set_context guard(ts->context);
4040

41-
uint32_t rv = cuGraphicsUnregisterResource((CUgraphicsResource) cuda_resource);
41+
int rv = cuGraphicsUnregisterResource((CUgraphicsResource) cuda_resource);
4242

4343
// OpenGL has already shut down. Ignore.
4444
if (rv == CUDA_ERROR_INVALID_GRAPHICS_CONTEXT)
@@ -78,8 +78,13 @@ void jit_unmap_graphics_resource(void *cuda_resource) {
7878
ThreadState *ts = thread_state(JitBackend::CUDA);
7979
scoped_set_context guard(ts->context);
8080

81-
cuda_check(
82-
cuGraphicsUnmapResources(1, (CUgraphicsResource *) &cuda_resource, 0));
81+
int rv = cuGraphicsUnmapResources(1, (CUgraphicsResource *) &cuda_resource, 0);
82+
83+
// OpenGL has already shut down. Ignore.
84+
if (rv == CUDA_ERROR_INVALID_GRAPHICS_CONTEXT)
85+
return;
86+
87+
cuda_check(rv);
8388
}
8489

8590
void jit_memcpy_2d_to_array_async(void *dst, const void *src, size_t src_pitch,

0 commit comments

Comments
 (0)