diff --git a/src/Gui/Quarter/QuarterWidgetP.cpp b/src/Gui/Quarter/QuarterWidgetP.cpp index 5f3267e5c8..7771c4b79b 100644 --- a/src/Gui/Quarter/QuarterWidgetP.cpp +++ b/src/Gui/Quarter/QuarterWidgetP.cpp @@ -169,13 +169,22 @@ QuarterWidgetP::removeFromCacheContext(QuarterWidgetP_cachecontext * context, co for (int i = 0; i < cachecontext_list->getLength(); i++) { if ((*cachecontext_list)[i] == context) { - // set the context while calling destructingContext() (might trigger OpenGL calls) - const_cast (widget)->makeCurrent(); - // fetch the cc_glglue context instance as a workaround for a bug fixed in Coin r12818 - (void) cc_glglue_instance(context->id); + QtGLContext* glcontext = widget->context(); + if (glcontext) { + // set the context while calling destructingContext() (might trigger OpenGL calls) + if (glcontext->isValid()) { + const_cast (widget)->makeCurrent(); + } + // fetch the cc_glglue context instance as a workaround for a bug fixed in Coin r12818 + (void) cc_glglue_instance(context->id); + } cachecontext_list->removeFast(i); SoContextHandler::destructingContext(context->id); - const_cast (widget)->doneCurrent(); + if (glcontext) { + if (glcontext->isValid()) { + const_cast (widget)->doneCurrent(); + } + } delete context; return; }