From 6ed23c2e7ddce0cb145569dc2b56648f851cbb05 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 27 Jun 2024 18:35:40 +0200 Subject: [PATCH] Gui: Fix crash in QuarterWidgetP::removeFromCacheContext Fixes #https://github.com/FreeCAD/FreeCAD/issues/14988 --- src/Gui/Quarter/QuarterWidgetP.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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; }