From e40323d3120c9297590641e82fa4616e272962a3 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Fri, 25 Jan 2019 16:44:23 +0000 Subject: [PATCH] Simplify shared timer reference counting in wxEventLoop for wxQT --- src/qt/evtloop.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/qt/evtloop.cpp b/src/qt/evtloop.cpp index 71ae83707a..1341ca115c 100644 --- a/src/qt/evtloop.cpp +++ b/src/qt/evtloop.cpp @@ -81,7 +81,7 @@ void wxQtIdleTimer::idle() namespace { - wxQtIdleTimer *gs_idleTimer = NULL; + wxObjectDataPtr gs_idleTimer; } void wxQtIdleTimer::ScheduleIdleCheck() @@ -95,13 +95,7 @@ wxQtEventLoopBase::wxQtEventLoopBase() { // Create an idle timer to run each time there are no events (timeout = 0) if ( !gs_idleTimer ) - { - gs_idleTimer = new wxQtIdleTimer(); - } - else - { - gs_idleTimer->IncRef(); - } + gs_idleTimer.reset(new wxQtIdleTimer()); m_qtIdleTimer = gs_idleTimer; m_qtEventLoop = new QEventLoop; @@ -109,8 +103,9 @@ wxQtEventLoopBase::wxQtEventLoopBase() wxQtEventLoopBase::~wxQtEventLoopBase() { - if ( gs_idleTimer->GetRefCount() <= 1 ) - gs_idleTimer = NULL; + //Clear the shared timer if this is the only external reference to it + if ( gs_idleTimer->GetRefCount() <= 2 ) + gs_idleTimer.reset(NULL); delete m_qtEventLoop; }