mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Detect emulated driver before casting to avoid crashs
This commit is contained in:
@@ -1392,7 +1392,7 @@ namespace BlackCore
|
||||
return args.join(' ');
|
||||
}
|
||||
|
||||
ISimulator *CApplication::getISimulator() const
|
||||
QPointer<ISimulator> CApplication::getISimulator() const
|
||||
{
|
||||
if (!this->getCoreFacade()) { return nullptr; }
|
||||
if (!this->getCoreFacade()->getCContextSimulator()) { return nullptr; }
|
||||
|
||||
@@ -323,7 +323,7 @@ namespace BlackCore
|
||||
// ----------------------- simulator ----------------------------------------
|
||||
|
||||
//! The simulator plugin, if available
|
||||
ISimulator *getISimulator() const;
|
||||
QPointer<ISimulator> getISimulator() const;
|
||||
|
||||
// ----------------------- contexts ----------------------------------------
|
||||
|
||||
|
||||
@@ -854,9 +854,9 @@ namespace BlackCore
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace BlackCore
|
||||
void gracefulShutdown();
|
||||
|
||||
//! Access to simulator (i.e. the plugin)
|
||||
ISimulator *simulator() const;
|
||||
QPointer<ISimulator> simulator() const;
|
||||
|
||||
//! Simulator available?
|
||||
bool hasSimulator() const { return this->simulator(); }
|
||||
|
||||
@@ -333,6 +333,12 @@ namespace BlackCore
|
||||
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)
|
||||
{
|
||||
if (this->isMyIdentifier(originator)) { return false; }
|
||||
|
||||
@@ -243,6 +243,9 @@ namespace BlackCore
|
||||
//! \copydoc BlackMisc::IProvider::asQObject
|
||||
virtual QObject *asQObject() override { return this; }
|
||||
|
||||
//! Is this the emulated driver just pretending to be P3D, FSX, or XPlane
|
||||
bool isEmulatedDriver() const;
|
||||
|
||||
//! \addtogroup swiftdotcommands
|
||||
//! @{
|
||||
//! <pre>
|
||||
|
||||
@@ -138,7 +138,8 @@ namespace BlackSimPlugin
|
||||
const CSimulatorPluginInfo plugin = sGui->getIContextSimulator()->getSimulatorPluginInfo();
|
||||
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() != m_simulator) { return nullptr; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user