diff --git a/src/xswiftbus/main.cpp b/src/xswiftbus/main.cpp index e4e833aeb..95d12f361 100644 --- a/src/xswiftbus/main.cpp +++ b/src/xswiftbus/main.cpp @@ -24,9 +24,9 @@ static XSwiftBus::CPlugin *g_plugin = nullptr; PLUGIN_API int XPluginStart(char *o_name, char *o_sig, char *o_desc) { -#if APL +#ifdef APL // https://developer.x-plane.com/2014/12/mac-plugin-developers-you-should-be-using-native-paths/ - XPLMEnableFeature("XPLM_USE_NATIVE_PATHS",1); + XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1); #endif INFO_LOG("XSwiftBus plugin starting"); @@ -58,6 +58,12 @@ PLUGIN_API void XPluginReceiveMessage(XPLMPluginID from, long msg, void *param) { if (from == XPLM_PLUGIN_XPLANE) { + if (!g_plugin || !g_plugin->isRunning()) + { + WARNING_LOG("Received message, but plugin NOT running"); + return; + } + switch (msg) { case XPLM_MSG_PLANE_LOADED: diff --git a/src/xswiftbus/plugin.cpp b/src/xswiftbus/plugin.cpp index 8fc2881d0..4b31105f7 100644 --- a/src/xswiftbus/plugin.cpp +++ b/src/xswiftbus/plugin.cpp @@ -85,7 +85,7 @@ namespace XSwiftBus void CPlugin::readConfig() { initXPlanePath(); - auto configFilePath = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xswiftbus" + g_sep + "xswiftbus.conf"; + const std::string configFilePath = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xswiftbus" + g_sep + "xswiftbus.conf"; m_pluginConfig.setFilePath(configFilePath); m_pluginConfig.parse(); m_pluginConfig.print(); @@ -175,10 +175,11 @@ namespace XSwiftBus float CPlugin::startServerDeferred(float, float, int, void *refcon) { auto *plugin = static_cast(refcon); - if (! plugin->m_isRunning) + if (!plugin->m_isRunning) { plugin->startServer(); plugin->m_isRunning = true; + INFO_LOG("XSwiftBus plugin started (deferred)"); } return 0; } diff --git a/src/xswiftbus/plugin.h b/src/xswiftbus/plugin.h index c7a56a66a..5b5bba165 100644 --- a/src/xswiftbus/plugin.h +++ b/src/xswiftbus/plugin.h @@ -56,6 +56,12 @@ namespace XSwiftBus //! Called by XPluginReceiveMessage when the aircraft is positioned at an airport void onAircraftRepositioned(); + //! Is running + bool isRunning() const { return m_isRunning; } + + //! Should stop + bool shouldStop() const { return m_shouldStop; } + private: CConfig m_pluginConfig; CDBusDispatcher m_dbusDispatcher; @@ -78,7 +84,7 @@ namespace XSwiftBus decltype(m_atisEnabled.get()) m_atisSaved = 0; std::thread m_dbusThread; - bool m_isRunning = false; + bool m_isRunning = false; bool m_shouldStop = false; void readConfig(); diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 8d77eee66..4a55b4fd8 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -14,6 +14,7 @@ #include #include +#include #include // clazy:excludeall=reserve-candidates @@ -33,7 +34,12 @@ namespace XSwiftBus char filename[256]; char path[512]; XPLMGetNthAircraftModel(XPLM_USER_AIRCRAFT, filename, path); - AcfProperties acfProperties = extractAcfProperties(path); + if (std::strlen(filename) < 1 || std::strlen(path) < 1) + { + WARNING_LOG("Aircraft changed, but NO path or file name"); + return; + } + const AcfProperties acfProperties = extractAcfProperties(path); emitAircraftModelChanged(path, filename, getAircraftLivery(), getAircraftIcaoCode(), acfProperties.modelString, acfProperties.modelName, getAircraftDescription()); }