Make sure TX/RX thread stops before audio devices do.

ms-wasapi-crash-fix-2
Mooneer Salem 2025-05-13 15:41:35 -07:00
parent 73cd6f49f7
commit f2d2179060
3 changed files with 14 additions and 7 deletions

View File

@ -2855,6 +2855,9 @@ void MainFrame::stopRxStream()
if (m_txThread)
{
m_txThread->terminateThread();
m_txThread->Wait();
if (txInSoundDevice)
{
txInSoundDevice->stop();
@ -2867,15 +2870,15 @@ void MainFrame::stopRxStream()
txOutSoundDevice.reset();
}
m_txThread->terminateThread();
m_txThread->Wait();
delete m_txThread;
m_txThread = nullptr;
}
if (m_rxThread)
{
m_rxThread->terminateThread();
m_rxThread->Wait();
if (rxInSoundDevice)
{
rxInSoundDevice->stop();
@ -2888,9 +2891,6 @@ void MainFrame::stopRxStream()
rxOutSoundDevice.reset();
}
m_rxThread->terminateThread();
m_rxThread->Wait();
delete m_txThread;
m_rxThread = nullptr;
}

View File

@ -515,7 +515,8 @@ void* TxRxThread::Entry()
void TxRxThread::OnExit()
{
// No actions required for exit.
// Free allocated buffer.
inputSamples_ = nullptr;
}
void TxRxThread::terminateThread()

View File

@ -58,6 +58,12 @@ public:
new short[std::max(inputSampleRate_, outputSampleRate_)],
std::default_delete<short[]>());
}
virtual ~TxRxThread()
{
// Free allocated buffer
inputSamples_ = nullptr;
}
// thread execution starts here
void *Entry();