diff --git a/toonz/sources/stdfx/shadingcontext.cpp b/toonz/sources/stdfx/shadingcontext.cpp index 75a68bd..9f00d3e 100644 --- a/toonz/sources/stdfx/shadingcontext.cpp +++ b/toonz/sources/stdfx/shadingcontext.cpp @@ -14,6 +14,7 @@ #include #include #include +#include // STD includes #include @@ -109,7 +110,15 @@ ShadingContext::ShadingContext() : m_imp(new Imp) { //-------------------------------------------------------- -ShadingContext::~ShadingContext() {} +ShadingContext::~ShadingContext() { +#ifdef MACOSX + // Destructor of QGLPixelBuffer calls QOpenGLContext::makeCurrent() internally, + // so the current thread must be the owner of QGLPixelBuffer context, + // when the destructor of m_imp->m_context is called. + + m_imp->m_pixelBuffer->context()->contextHandle()->moveToThread(QThread::currentThread()); +#endif +} //-------------------------------------------------------- @@ -154,11 +163,21 @@ USE HARDWARE ACCELERATION */ //-------------------------------------------------------- -void ShadingContext::makeCurrent() { m_imp->m_pixelBuffer->makeCurrent(); } +void ShadingContext::makeCurrent() { +#ifdef MACOSX + m_imp->m_pixelBuffer->context()->contextHandle()->moveToThread(QThread::currentThread()); +#endif + m_imp->m_pixelBuffer->makeCurrent(); +} //-------------------------------------------------------- -void ShadingContext::doneCurrent() { m_imp->m_pixelBuffer->doneCurrent(); } +void ShadingContext::doneCurrent() { +#ifdef MACOSX + m_imp->m_pixelBuffer->context()->contextHandle()->moveToThread(0); +#endif + m_imp->m_pixelBuffer->doneCurrent(); +} //--------------------------------------------------------