Ref T260, interpolator deferred init fix. Make sure lambda is not called when interpolator is deleted.

This commit is contained in:
Klaus Basan
2018-04-13 23:05:39 +02:00
committed by Roland Winklmeier
parent 08c27338aa
commit 9fa3e415f5
2 changed files with 19 additions and 13 deletions

View File

@@ -47,13 +47,18 @@ namespace BlackMisc
if (remoteAircraftProvider) if (remoteAircraftProvider)
{ {
this->setRemoteAircraftProvider(remoteAircraftProvider); this->setRemoteAircraftProvider(remoteAircraftProvider);
QTimer::singleShot(2500, [ = ] QObject::connect(&m_initTimer, &QTimer::timeout, [ = ] { this->deferredInit(); });
m_initTimer.setSingleShot(true);
m_initTimer.start(2500);
}
this->attachLogger(logger);
}
template<typename Derived>
void CInterpolator<Derived>::deferredInit()
{ {
if (m_model.hasModelString()) { return; } // set in-between if (m_model.hasModelString()) { return; } // set in-between
this->initCorrespondingModel(); this->initCorrespondingModel();
});
}
this->attachLogger(logger);
} }
template<typename Derived> template<typename Derived>
@@ -268,15 +273,10 @@ namespace BlackMisc
template<typename Derived> template<typename Derived>
CAircraftParts CInterpolator<Derived>::getInterpolatedOrGuessedParts(qint64 currentTimeMsSinceEpoch, const CInterpolationAndRenderingSetupPerCallsign &setup, CPartsStatus &partsStatus, bool log) const CAircraftParts CInterpolator<Derived>::getInterpolatedOrGuessedParts(qint64 currentTimeMsSinceEpoch, const CInterpolationAndRenderingSetupPerCallsign &setup, CPartsStatus &partsStatus, bool log) const
{ {
CAircraftParts parts = this->getInterpolatedParts(currentTimeMsSinceEpoch, setup, partsStatus, log); CAircraftParts parts;
if (setup.isAircraftPartsEnabled()) { parts = this->getInterpolatedParts(currentTimeMsSinceEpoch, setup, partsStatus, log); }
if (!partsStatus.isSupportingParts()) if (!partsStatus.isSupportingParts())
{ {
if (!m_model.hasModelString())
{
const CSimulatedAircraft aircraft = this->getAircraftInRangeForCallsign(m_callsign);
// m_model = aircraft.getModel();
}
// check if model has been thru model matching // check if model has been thru model matching
if (m_model.hasModelString()) if (m_model.hasModelString())
{ {

View File

@@ -26,6 +26,7 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QtGlobal> #include <QtGlobal>
#include <QTimer>
namespace BlackMisc namespace BlackMisc
{ {
@@ -102,6 +103,7 @@ namespace BlackMisc
PhysicalQuantities::CLength m_cg { 0, nullptr } ; //!< fetched once, stays constant PhysicalQuantities::CLength m_cg { 0, nullptr } ; //!< fetched once, stays constant
Aviation::CAircraftSituation m_lastInterpolation { Aviation::CAircraftSituation::null() }; //!< latest interpolation Aviation::CAircraftSituation m_lastInterpolation { Aviation::CAircraftSituation::null() }; //!< latest interpolation
CAircraftModel m_model; //!< corresponding model CAircraftModel m_model; //!< corresponding model
qint64 m_situationsLastModifiedUsed { -1 }; //!< based on situations last updated
//! Equal double values? //! Equal double values?
static bool doubleEpsilonEqual(double d1, double d2) static bool doubleEpsilonEqual(double d1, double d2)
@@ -138,10 +140,14 @@ namespace BlackMisc
private: private:
CInterpolationLogger *m_logger = nullptr; CInterpolationLogger *m_logger = nullptr;
QTimer m_initTimer; //!< timer to init model, will be deleted when interpolator is deleted and cancel the call
//! Log parts //! Log parts
void logParts(qint64 timestamp, const Aviation::CAircraftParts &parts, int partsNo, bool empty, bool log) const; void logParts(qint64 timestamp, const Aviation::CAircraftParts &parts, int partsNo, bool empty, bool log) const;
//! Deferred init
void deferredInit();
Derived *derived() { return static_cast<Derived *>(this); } Derived *derived() { return static_cast<Derived *>(this); }
const Derived *derived() const { return static_cast<const Derived *>(this); } const Derived *derived() const { return static_cast<const Derived *>(this); }
}; };