Skip to content

Commit

Permalink
Merge pull request #372 from lassoan/371-ensure-base-style-infinite-r…
Browse files Browse the repository at this point in the history
…ecursion-crash

Prevent reentrant calling of ctkProxyStyle::ensureBaseStyle()
  • Loading branch information
jcfr committed Oct 1, 2013
2 parents 90000c3 + a8ebaef commit f64b68a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Libs/Widgets/ctkProxyStyle.cpp
Expand Up @@ -38,11 +38,13 @@ class ctkProxyStylePrivate
private:
ctkProxyStylePrivate(ctkProxyStyle& object);
mutable QPointer <QStyle> baseStyle;
mutable bool ensureBaseStyleInProgress;
};

// ----------------------------------------------------------------------------
ctkProxyStylePrivate::ctkProxyStylePrivate(ctkProxyStyle& object)
: q_ptr(&object)
, ensureBaseStyleInProgress(false)
{
}

Expand Down Expand Up @@ -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*>(
Expand All @@ -115,6 +123,7 @@ void ctkProxyStyle::ensureBaseStyle() const
baseStyle = proxy ? proxy->baseStyle() : 0;
}
d->setBaseStyle(proxyStyle, proxyBaseStyle);
d->ensureBaseStyleInProgress = false;
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit f64b68a

Please sign in to comment.