diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index bfcf314e8a..b5d7a423e0 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -244015,7 +244015,12 @@ public: void deleteContext() { makeInactive(); - wglDeleteContext (renderContext); + + if (renderContext != 0) + { + wglDeleteContext (renderContext); + renderContext = 0; + } } bool makeActive() const throw() @@ -259143,8 +259148,12 @@ public: { makeInactive(); - ScopedXLock xlock; - glXDestroyContext (display, renderContext); + if (renderContext != 0) + { + ScopedXLock xlock; + glXDestroyContext (display, renderContext); + renderContext = 0; + } } bool makeActive() const throw() @@ -266828,6 +266837,9 @@ public: { makeInactive(); [renderContext clearDrawable]; + [renderContext setView: nil]; + [view setOpenGLContext: nil]; + renderContext = nil; } bool makeActive() const throw() @@ -272417,6 +272429,9 @@ public: { makeInactive(); [renderContext clearDrawable]; + [renderContext setView: nil]; + [view setOpenGLContext: nil]; + renderContext = nil; } bool makeActive() const throw() diff --git a/juce_amalgamated.h b/juce_amalgamated.h index f81e2e48bd..03a38856a9 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -56878,6 +56878,10 @@ public: virtual void* getRawContext() const throw() = 0; /** Deletes the context. + + This must only be called on the message thread, or will deadlock. + On background threads, call getCurrentContext()->deleteContext(), but be careful not + to call any other OpenGL function afterwards. This doesn't touch other resources, such as window handles, etc. You'll probably never have to call this method directly. */ diff --git a/src/gui/components/special/juce_OpenGLComponent.h b/src/gui/components/special/juce_OpenGLComponent.h index d3ce5a5124..5b2bad250f 100644 --- a/src/gui/components/special/juce_OpenGLComponent.h +++ b/src/gui/components/special/juce_OpenGLComponent.h @@ -147,6 +147,10 @@ public: virtual void* getRawContext() const throw() = 0; /** Deletes the context. + + This must only be called on the message thread, or will deadlock. + On background threads, call getCurrentContext()->deleteContext(), but be careful not + to call any other OpenGL function afterwards. This doesn't touch other resources, such as window handles, etc. You'll probably never have to call this method directly. */ diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index 5a1704cd1a..81f3a08b92 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -3244,8 +3244,12 @@ public: { makeInactive(); - ScopedXLock xlock; - glXDestroyContext (display, renderContext); + if (renderContext != 0) + { + ScopedXLock xlock; + glXDestroyContext (display, renderContext); + renderContext = 0; + } } bool makeActive() const throw() diff --git a/src/native/mac/juce_mac_OpenGLComponent.mm b/src/native/mac/juce_mac_OpenGLComponent.mm index 3c5f0b655c..3a300665f9 100644 --- a/src/native/mac/juce_mac_OpenGLComponent.mm +++ b/src/native/mac/juce_mac_OpenGLComponent.mm @@ -184,6 +184,9 @@ public: { makeInactive(); [renderContext clearDrawable]; + [renderContext setView: nil]; + [view setOpenGLContext: nil]; + renderContext = nil; } bool makeActive() const throw() diff --git a/src/native/windows/juce_win32_OpenGLComponent.cpp b/src/native/windows/juce_win32_OpenGLComponent.cpp index f7e5b16913..651c5f482d 100644 --- a/src/native/windows/juce_win32_OpenGLComponent.cpp +++ b/src/native/windows/juce_win32_OpenGLComponent.cpp @@ -123,7 +123,12 @@ public: void deleteContext() { makeInactive(); - wglDeleteContext (renderContext); + + if (renderContext != 0) + { + wglDeleteContext (renderContext); + renderContext = 0; + } } bool makeActive() const throw()