nativestreamer: fix thread cleanup race
- Disconnect finished signal before waiting in stop() to prevent onThreadFinished from running after thread is deleted - Use deleteLater() in onThreadFinished for safe cleanup during restart - Remove redundant quit() call (QThread::create threads have no event loop)
This commit is contained in:
parent
ca4dc2d412
commit
16883248f0
|
|
@ -61,9 +61,13 @@ void NativeStreamer::stop()
|
|||
}
|
||||
|
||||
if (m_thread) {
|
||||
m_thread->quit();
|
||||
m_thread->wait(1000);
|
||||
if (m_thread->isRunning()) {
|
||||
// Disconnect to prevent onThreadFinished from running after we delete
|
||||
disconnect(m_thread, &QThread::finished, this, &NativeStreamer::onThreadFinished);
|
||||
|
||||
// Wait for thread to finish (it should exit after fid is closed)
|
||||
if (!m_thread->wait(2000)) {
|
||||
// Thread didn't exit in time, force terminate
|
||||
qWarning() << "NativeStreamer: thread didn't exit cleanly, terminating";
|
||||
m_thread->terminate();
|
||||
m_thread->wait();
|
||||
}
|
||||
|
|
@ -84,8 +88,9 @@ void NativeStreamer::setGuard(std::function<bool()> guard)
|
|||
|
||||
void NativeStreamer::onThreadFinished()
|
||||
{
|
||||
// Thread finished naturally (not via stop()) - clean up and maybe restart
|
||||
if (m_thread) {
|
||||
delete m_thread;
|
||||
m_thread->deleteLater();
|
||||
m_thread = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in New Issue