Detect emulated driver before casting to avoid crashs

This commit is contained in:
Klaus Basan
2018-11-04 22:03:35 +01:00
parent c056d74820
commit dfd33e40c1
7 changed files with 16 additions and 6 deletions

View File

@@ -1392,7 +1392,7 @@ namespace BlackCore
return args.join(' '); return args.join(' ');
} }
ISimulator *CApplication::getISimulator() const QPointer<ISimulator> CApplication::getISimulator() const
{ {
if (!this->getCoreFacade()) { return nullptr; } if (!this->getCoreFacade()) { return nullptr; }
if (!this->getCoreFacade()->getCContextSimulator()) { return nullptr; } if (!this->getCoreFacade()->getCContextSimulator()) { return nullptr; }

View File

@@ -323,7 +323,7 @@ namespace BlackCore
// ----------------------- simulator ---------------------------------------- // ----------------------- simulator ----------------------------------------
//! The simulator plugin, if available //! The simulator plugin, if available
ISimulator *getISimulator() const; QPointer<ISimulator> getISimulator() const;
// ----------------------- contexts ---------------------------------------- // ----------------------- contexts ----------------------------------------

View File

@@ -854,9 +854,9 @@ namespace BlackCore
return false; return false;
} }
ISimulator *CContextSimulator::simulator() const QPointer<ISimulator> CContextSimulator::simulator() const
{ {
if (!this->isSimulatorAvailable()) { return nullptr; } if (!this->isSimulatorAvailable() || !m_simulatorPlugin.second) { return nullptr; }
return m_simulatorPlugin.second; return m_simulatorPlugin.second;
} }

View File

@@ -138,7 +138,7 @@ namespace BlackCore
void gracefulShutdown(); void gracefulShutdown();
//! Access to simulator (i.e. the plugin) //! Access to simulator (i.e. the plugin)
ISimulator *simulator() const; QPointer<ISimulator> simulator() const;
//! Simulator available? //! Simulator available?
bool hasSimulator() const { return this->simulator(); } bool hasSimulator() const { return this->simulator(); }

View File

@@ -333,6 +333,12 @@ namespace BlackCore
ISimulationEnvironmentProvider::resetSimulationEnvironmentStatistics(); ISimulationEnvironmentProvider::resetSimulationEnvironmentStatistics();
} }
bool ISimulator::isEmulatedDriver() const
{
const QString className = this->metaObject()->className();
return className.contains("emulated", Qt::CaseInsensitive);
}
bool ISimulator::parseCommandLine(const QString &commandLine, const CIdentifier &originator) bool ISimulator::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
{ {
if (this->isMyIdentifier(originator)) { return false; } if (this->isMyIdentifier(originator)) { return false; }

View File

@@ -243,6 +243,9 @@ namespace BlackCore
//! \copydoc BlackMisc::IProvider::asQObject //! \copydoc BlackMisc::IProvider::asQObject
virtual QObject *asQObject() override { return this; } virtual QObject *asQObject() override { return this; }
//! Is this the emulated driver just pretending to be P3D, FSX, or XPlane
bool isEmulatedDriver() const;
//! \addtogroup swiftdotcommands //! \addtogroup swiftdotcommands
//! @{ //! @{
//! <pre> //! <pre>

View File

@@ -138,7 +138,8 @@ namespace BlackSimPlugin
const CSimulatorPluginInfo plugin = sGui->getIContextSimulator()->getSimulatorPluginInfo(); const CSimulatorPluginInfo plugin = sGui->getIContextSimulator()->getSimulatorPluginInfo();
if (plugin.isEmulatedPlugin()) { return nullptr; } // cast would fail if (plugin.isEmulatedPlugin()) { return nullptr; } // cast would fail
ISimulator *simulator = sGui->getISimulator(); ISimulator *simulator = sGui->getISimulator().data();
if (!simulator || simulator->isEmulatedDriver()) { return nullptr; }
if (!simulator->getSimulatorInfo().isFsxP3DFamily()) { return nullptr; } if (!simulator->getSimulatorInfo().isFsxP3DFamily()) { return nullptr; }
if (simulator->getSimulatorInfo() != m_simulator) { return nullptr; } if (simulator->getSimulatorInfo() != m_simulator) { return nullptr; }