From ee195e3e207a4d79a65b5afbb16ea8784e4fb17d Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Fri, 3 Apr 2015 13:30:22 +0200 Subject: [PATCH] Handle cases when no simulator is available properly in simulator context In the past core was always loading one simulator plugin by default. This has changed recently with the listeners. So m_simulator is not guaranteed to be valid. A proper fix in the future is to not even call them. At the moment they are hard wired to network. --- src/blackcore/context_simulator_impl.cpp | 43 ++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index 3e852a935..e4723090b 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -531,7 +531,15 @@ namespace BlackCore void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft) { - Q_ASSERT(m_simulator); + // todo: + // This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if(!m_simulator) + { + // Do something if no simulator is running + return; + } + Q_ASSERT(m_simulator->simulator); Q_ASSERT(!remoteAircraft.getCallsign().isEmpty()); @@ -540,7 +548,15 @@ namespace BlackCore void CContextSimulator::ps_removedRemoteAircraft(const CCallsign &callsign) { - Q_ASSERT(m_simulator); + // todo: + // This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if(!m_simulator) + { + // Do something if no simulator is running + return; + } + Q_ASSERT(m_simulator->simulator); m_simulator->simulator->removeRemoteAircraft(callsign); @@ -561,10 +577,17 @@ namespace BlackCore void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages) { - Q_ASSERT(m_simulator); - Q_ASSERT(m_simulator->simulator); + // todo: + // This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if(!m_simulator) + { + // Do something if no simulator is running + return; + } - for (auto &tm: textMessages) + Q_ASSERT(m_simulator->simulator); + for (const auto &tm : textMessages) { m_simulator->simulator->displayTextMessage(tm); } @@ -591,7 +614,15 @@ namespace BlackCore void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CAircraft &ownAircraft, const QString &originator) { - Q_ASSERT(m_simulator); + // todo: + // This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if(!m_simulator) + { + // Do something if no simulator is running + return; + } + Q_ASSERT(m_simulator->simulator); // avoid loops