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

View File

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

View File

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