-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Channel deleted before Channel GUI can result in a crash #1332
Comments
This is very problematic because the destruction action is initiated from the GUI thus it emits a |
Well this seems to work: --- a/sdrgui/device/deviceuiset.cpp
+++ b/sdrgui/device/deviceuiset.cpp
@@ -723,8 +723,17 @@ void DeviceUISet::handleChannelGUIClosing(ChannelGUI* channelGUI)
{
if (it->m_gui == channelGUI)
{
- m_deviceSet->removeChannelInstance(it->m_channelAPI);
- it->m_channelAPI->destroy();
+ ChannelAPI *channelAPI = it->m_channelAPI;
+ m_deviceSet->removeChannelInstance(channelAPI);
+ qDebug("DeviceUISet::handleChannelGUIClosing: channelAPI: %p", channelAPI);
+
+ QObject::connect(
+ channelGUI,
+ &ChannelGUI::destroyed,
+ this,
+ [this, channelAPI](){ this->handleDeleteChannel(channelAPI); }
+ );
+
m_channelInstanceRegistrations.erase(it);
break;
}
@@ -736,6 +745,12 @@ void DeviceUISet::handleChannelGUIClosing(ChannelGUI* channelGUI)
}
}
+void DeviceUISet::handleDeleteChannel(ChannelAPI *channelAPI)
+{
+ qDebug("DeviceUISet::handleDeleteChannel: channelAPI: %p", channelAPI);
+ channelAPI->destroy();
+}
+
int DeviceUISet::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const
{
return m_spectrumVis->webapiSpectrumSettingsGet(response, errorMessage); This yields when channel is closed from GUI:
|
The same issue appears when initiating deletion from the main window exit. In this case it takes a different path via
|
The latter is fixed easily along with --- a/sdrgui/device/deviceuiset.cpp
+++ b/sdrgui/device/deviceuiset.cpp
@@ -161,8 +161,8 @@ void DeviceUISet::freeChannels()
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceUISet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelAPI->getURI()));
- m_channelInstanceRegistrations[i].m_channelAPI->destroy();
m_channelInstanceRegistrations[i].m_gui->destroy();
+ m_channelInstanceRegistrations[i].m_channelAPI->destroy();
}
m_channelInstanceRegistrations.clear();
@@ -176,8 +176,8 @@ void DeviceUISet::deleteChannel(int channelIndex)
qDebug("DeviceUISet::deleteChannel: delete channel [%s] at %d",
qPrintable(m_channelInstanceRegistrations[channelIndex].m_channelAPI->getURI()),
channelIndex);
- m_channelInstanceRegistrations[channelIndex].m_channelAPI->destroy();
m_channelInstanceRegistrations[channelIndex].m_gui->destroy();
+ m_channelInstanceRegistrations[channelIndex].m_channelAPI->destroy();
m_channelInstanceRegistrations.removeAt(channelIndex);
}
|
Needs to be done for Features as well (FeatureUISet) |
I've been trying to track down some of the reported crashes - here's one possible cause found running with a debug build on windows.
It seems the Channel object is deleted before the Channel GUI. E.g. if we add some debug to the destructors in say the NFMDemod:
2022-07-08 23:32:49.197 (D) NFMDemod::~NFMDemod
2022-07-08 23:32:49.197 (D) DSPDeviceSourceEngine::removeSink: NFMDemod
2022-07-08 23:32:49.198 (D) DSPDeviceSourceEngine::handleSynchronousMessages: DSPRemoveBasebandSampleSink
2022-07-08 23:32:49.198 (D) AudioDeviceManager::removeAudioSink: 0x23fca2cdaf0
2022-07-08 23:32:49.199 (D) MessageQueue::~MessageQueue: message: NFMDemodBaseband::MsgConfigureNFMDemodBaseband was still in queue
2022-07-08 23:32:49.199 (D) MessageQueue::~MessageQueue: message: DSPSignalNotification was still in queue
2022-07-08 23:32:49.200 (D) MessageQueue::~MessageQueue: message: NFMDemodBaseband::MsgConfigureNFMDemodBaseband was still in queue
2022-07-08 23:32:49.200 (D) MessageQueue::~MessageQueue: message: NFMDemodBaseband::MsgConfigureNFMDemodBaseband was still in queue
2022-07-08 23:32:49.201 (D) MessageQueue::~MessageQueue: message: NFMDemodBaseband::MsgConfigureNFMDemodBaseband was still in queue
2022-07-08 23:32:49.201 (D) NFMDemod::~NFMDemod complete
2022-07-08 23:32:49.202 (D) NFMDemodGUI::~NFMDemodGUI
We can see the NFMDemod destructor competes before the NFMDemodGUI destructor is called.
This can occasionally crash if the NFMDemodGUI::tick() method is called inbetween the two, because tick() uses the pointer to the deleted object:
The same problem occurs in many of the channel GUIs that call getMagSqLevels in a similar way.
The text was updated successfully, but these errors were encountered: