diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 6c254182a454..5fd4c4e0b948 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -483,8 +483,19 @@ void OpenGLContext::prepareForYield() SAL_INFO("vcl.opengl", "Unbinding contexts in preparation for yield"); - if( pCurrentCtx->isCurrent() ) - pCurrentCtx->resetCurrent(); + // Find the first context that is current and reset it. + // Usually the last context is the current, but not in case a new + // OpenGLContext is created already but not yet initialized. + while (pCurrentCtx.is()) + { + if (pCurrentCtx->isCurrent()) + { + pCurrentCtx->resetCurrent(); + break; + } + + pCurrentCtx = pCurrentCtx->mpPrevContext; + } assert (!hasCurrent()); }