From cdb78c903f357aea91bd3a0bc8fd11861bf4881f Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 1 Dec 2023 11:54:14 +0000 Subject: [PATCH] SDRPlay V3 API - don't call close unless open was a success, as will crash on Mac, --- .../sdrplayv3/sdrplayv3plugin.cpp | 33 +++++++++++++------ .../samplesource/sdrplayv3/sdrplayv3plugin.h | 1 + 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugins/samplesource/sdrplayv3/sdrplayv3plugin.cpp b/plugins/samplesource/sdrplayv3/sdrplayv3plugin.cpp index bed1a3155..9c463b311 100644 --- a/plugins/samplesource/sdrplayv3/sdrplayv3plugin.cpp +++ b/plugins/samplesource/sdrplayv3/sdrplayv3plugin.cpp @@ -43,25 +43,38 @@ static constexpr const char* const m_hardwareID = "SDRplayV3"; static constexpr const char* const m_deviceTypeID = SDRPLAYV3_DEVICE_TYPE_ID; SDRPlayV3Plugin::SDRPlayV3Plugin(QObject* parent) : - QObject(parent) + QObject(parent), + m_opened(false) { sdrplay_api_ErrT err; float ver = 0.0f; - qDebug() << "SDRPlayV3Plugin: calling sdrplay_api_Open()"; - if ((err = sdrplay_api_Open()) != sdrplay_api_Success) + if ((err = sdrplay_api_Open()) == sdrplay_api_Success) + { + m_opened = true; + + if ((err = sdrplay_api_ApiVersion(&ver)) == sdrplay_api_Success) + { + if (ver != SDRPLAY_API_VERSION) { + qCritical() << "SDRPlayV3Plugin::SDRPlayV3Plugin: SDRPlay API versions do not match " << ver << " " << SDRPLAY_API_VERSION; + } + } + else + { + qCritical() << "SDRPlayV3Plugin::SDRPlayV3Plugin: failed to get SDRPlay API version."; + } + } + else + { qCritical() << "SDRPlayV3Plugin::SDRPlayV3Plugin: sdrplay_api_Open() was unsuccessful. " << sdrplay_api_GetErrorString(err); - - if ((err = sdrplay_api_ApiVersion(&ver)) != sdrplay_api_Success) - qCritical() << "SDRPlayV3Plugin::SDRPlayV3Plugin: failed to get SDRPlay API version."; - - if (ver != SDRPLAY_API_VERSION) - qCritical() << "SDRPlayV3Plugin::SDRPlayV3Plugin: SDRPlay API versions do not match " << ver << " " << SDRPLAY_API_VERSION; + } } SDRPlayV3Plugin::~SDRPlayV3Plugin() { - sdrplay_api_Close(); + if (m_opened) { + sdrplay_api_Close(); + } } const PluginDescriptor& SDRPlayV3Plugin::getPluginDescriptor() const diff --git a/plugins/samplesource/sdrplayv3/sdrplayv3plugin.h b/plugins/samplesource/sdrplayv3/sdrplayv3plugin.h index d747b221c..05c504f68 100644 --- a/plugins/samplesource/sdrplayv3/sdrplayv3plugin.h +++ b/plugins/samplesource/sdrplayv3/sdrplayv3plugin.h @@ -52,6 +52,7 @@ public: virtual DeviceWebAPIAdapter* createDeviceWebAPIAdapter() const; private: + bool m_opened; // Whether sdrplay_api_Open was successful static const PluginDescriptor m_pluginDescriptor; };