mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
Detect emulated driver before casting to avoid crashs
This commit is contained in:
@@ -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; }
|
||||||
|
|||||||
@@ -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 ----------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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(); }
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user