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

@@ -43,19 +43,24 @@ namespace BlackMisc
// normally when created m_cg is still null since there is no CG in the provider yet
if (simEnvProvider) { this->setSimulationEnvironmentProvider(simEnvProvider); }
if (setupProvider) { this->setInterpolationSetupProvider(setupProvider); }
if (setupProvider) { this->setInterpolationSetupProvider(setupProvider); }
if (remoteAircraftProvider)
{
this->setRemoteAircraftProvider(remoteAircraftProvider);
QTimer::singleShot(2500, [ = ]
{
if (m_model.hasModelString()) { return; } // set in-between
this->initCorrespondingModel();
});
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
this->initCorrespondingModel();
}
template<typename Derived>
bool CInterpolator<Derived>::verifyInterpolationSituations(const CAircraftSituation &oldest, const CAircraftSituation &newer, const CAircraftSituation &latest, const CInterpolationAndRenderingSetupPerCallsign &setup)
{
@@ -268,15 +273,10 @@ namespace BlackMisc
template<typename Derived>
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 (!m_model.hasModelString())
{
const CSimulatedAircraft aircraft = this->getAircraftInRangeForCallsign(m_callsign);
// m_model = aircraft.getModel();
}
// check if model has been thru model matching
if (m_model.hasModelString())
{

View File

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