From a89e042ff8fd10c5d2a92a5c1e457c982f2ad28b Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 11 May 2017 17:44:08 +0100 Subject: [PATCH] Prevent inserting default-constructed elements in CSimulatorFsxCommon::m_simConnectObjects. Hopefully this fixes null pointer dereference of CSimConnectObject::m_interpolator. --- .../simulator/fsxcommon/simconnectobject.cpp | 4 ++++ .../simulator/fsxcommon/simulatorfsxcommon.cpp | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.cpp b/src/plugins/simulator/fsxcommon/simconnectobject.cpp index 7b2f9f304..c294632b5 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectobject.cpp @@ -31,11 +31,13 @@ namespace BlackSimPlugin void CSimConnectObject::addAircraftParts(const CAircraftParts &parts) { + Q_ASSERT(m_interpolator); m_interpolator->addAircraftParts(parts); } void CSimConnectObject::addAircraftSituation(const CAircraftSituation &situation) { + Q_ASSERT(m_interpolator); m_interpolator->addAircraftSituation(situation); } @@ -76,11 +78,13 @@ namespace BlackSimPlugin void CSimConnectObject::toggleInterpolatorMode() { + Q_ASSERT(m_interpolator); this->m_interpolator->toggleMode(); } bool CSimConnectObject::setInterpolatorMode(CInterpolatorMulti::Mode mode) { + Q_ASSERT(m_interpolator); return this->m_interpolator->setMode(mode); } diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 53d93d0d3..6879092d8 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -1072,7 +1072,7 @@ namespace BlackSimPlugin objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(DataDefinitionRemoteAircraftPartsWithoutLights), &ddRemoteAircraftPartsWithoutLights); - if (hr == S_OK) + if (hr == S_OK && m_simConnectObjects.contains(simObj.getCallsign())) { // Update data CSimConnectObject &objUdpate = m_simConnectObjects[simObj.getCallsign()]; @@ -1103,8 +1103,11 @@ namespace BlackSimPlugin const CCallsign callsign(simObj.getCallsign()); // Update data - CSimConnectObject &simObjToUpdate = m_simConnectObjects[callsign]; - simObjToUpdate.setLightsAsSent(lightsWanted); + if (m_simConnectObjects.contains(callsign)) + { + CSimConnectObject &simObjToUpdate = m_simConnectObjects[callsign]; + simObjToUpdate.setLightsAsSent(lightsWanted); + } // state available, then I can toggle if (!lightsIsState.isNull()) @@ -1141,6 +1144,7 @@ namespace BlackSimPlugin CLogMessage(this).info("Missing light state for '%1'") << callsign; QTimer::singleShot(2500, this, [ = ] { + if (!m_simConnectObjects.contains(callsign)) { return; } const CSimConnectObject currentSimObj = m_simConnectObjects[callsign]; if (!currentSimObj.hasValidRequestAndObjectId()) { return; } // stale if (lightsWanted != currentSimObj.getLightsAsSent()) { return; } // changed in between @@ -1229,7 +1233,8 @@ namespace BlackSimPlugin m_hSimConnect, simObject.getRequestId() + RequestSimDataOffset, CSimConnectDefinitions::DataRemoteAircraftSimData, simObject.getObjectId(), period); - if (result == S_OK) + + if (result == S_OK && m_simConnectObjects.contains(simObject.getCallsign())) { m_simConnectObjects[simObject.getCallsign()].setSimDataPeriod(period); return true;