Przeglądaj źródła

Merge pull request #372 from lassoan/371-ensure-base-style-infinite-recursion-crash

Prevent reentrant calling of ctkProxyStyle::ensureBaseStyle()
Jean-Christophe Fillion-Robin 11 lat temu
rodzic
commit
f64b68acd7
1 zmienionych plików z 9 dodań i 0 usunięć
  1. 9 0
      Libs/Widgets/ctkProxyStyle.cpp

+ 9 - 0
Libs/Widgets/ctkProxyStyle.cpp

@@ -38,11 +38,13 @@ public:
 private:
   ctkProxyStylePrivate(ctkProxyStyle& object);
   mutable QPointer <QStyle> baseStyle;
+  mutable bool ensureBaseStyleInProgress;
 };
 
 // ----------------------------------------------------------------------------
 ctkProxyStylePrivate::ctkProxyStylePrivate(ctkProxyStyle& object)
   : q_ptr(&object)
+  , ensureBaseStyleInProgress(false)
 {
 }
 
@@ -102,6 +104,12 @@ ctkProxyStyle::~ctkProxyStyle()
 void ctkProxyStyle::ensureBaseStyle() const
 {
   Q_D(const ctkProxyStyle);
+  if (d->ensureBaseStyleInProgress)
+  {
+    // avoid infinite loop
+    return;
+  }
+  d->ensureBaseStyleInProgress = true;  
   d->baseStyle = this->baseStyle();
   // Set the proxy to the entire hierarchy.
   QProxyStyle* proxyStyle = const_cast<QProxyStyle*>(qobject_cast<const QProxyStyle*>(
@@ -115,6 +123,7 @@ void ctkProxyStyle::ensureBaseStyle() const
     baseStyle = proxy ? proxy->baseStyle() : 0;
     }
   d->setBaseStyle(proxyStyle, proxyBaseStyle);
+  d->ensureBaseStyleInProgress = false;
 }
 
 // ----------------------------------------------------------------------------