From a8ebaefdaf2fdf9fc3208e57a7b3c9a82184fee8 Mon Sep 17 00:00:00 2001 From: Andras Lasso Date: Tue, 1 Oct 2013 12:43:21 -0400 Subject: [PATCH] Prevent reentrant calling of ctkProxyStyle::ensureBaseStyle() If ctkProxyStyle::ensureBaseStyle() is already in progress for an object then further ctkProxyStyle::ensureBaseStyle() calls for the same object are ignored. This patch is tested and does prevent the crashes. There doesn't seem to be any side-effect. --- Libs/Widgets/ctkProxyStyle.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Libs/Widgets/ctkProxyStyle.cpp b/Libs/Widgets/ctkProxyStyle.cpp index a1598298c..c27f2397e 100644 --- a/Libs/Widgets/ctkProxyStyle.cpp +++ b/Libs/Widgets/ctkProxyStyle.cpp @@ -38,11 +38,13 @@ class ctkProxyStylePrivate private: ctkProxyStylePrivate(ctkProxyStyle& object); mutable QPointer 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(qobject_cast( @@ -115,6 +123,7 @@ void ctkProxyStyle::ensureBaseStyle() const baseStyle = proxy ? proxy->baseStyle() : 0; } d->setBaseStyle(proxyStyle, proxyBaseStyle); + d->ensureBaseStyleInProgress = false; } // ----------------------------------------------------------------------------