From a7c704ae2f88fbc3813f470cf8cd4ae566815b16 Mon Sep 17 00:00:00 2001 From: kappaOne Date: Sun, 14 Apr 2013 14:14:36 +0100 Subject: [PATCH] Workaround Nvidia driver bug which crashed the OS when releasing a shared context by not releasing shared contexts. --- .../macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m | 4 +++- .../org_lwjgl_opengl_MacOSXContextImplementation.m | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m b/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m index 31fc06e4..5460b6db 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m @@ -285,7 +285,9 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle } - (void)releaseCGLContext:(CGLContextObj)glContext { - CGLDestroyContext(contextObject); + CGLClearDrawable(contextObject); + // disable releasing context due to nvidia crash bug when releasing shared contexts + //CGLDestroyContext(contextObject); } - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m b/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m index 64a5b804..5c106d00 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m @@ -219,10 +219,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nDestro [context_info->peer_info->glLayer performSelectorOnMainThread:@selector(removeLayer) withObject:nil waitUntilDone:YES]; [context_info->peer_info->glLayer release]; context_info->peer_info->glLayer = nil; + // don't release context due to nvidia driver bug when releasing shared contexts + [context_info->context retain]; } - // clearDrawable on main thread to ensure its not in use - [context_info->context performSelectorOnMainThread:@selector(clearDrawable) withObject:nil waitUntilDone:YES]; + [context_info->context clearDrawable]; if (context_info->peer_info->isWindowed) { [context_info->peer_info->window_info->view setOpenGLContext:nil]; @@ -230,6 +231,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nDestro context_info->context = nil; context_info->peer_info->window_info->context = nil; } + else { + // don't release context due to nvidia driver bug when releasing shared contexts + //[context_info->context release]; + //context_info->context = nil; + } [pool release]; }