diff --git a/gui/nativestreamer.cpp b/gui/nativestreamer.cpp index 89d99a1..c04a42d 100644 --- a/gui/nativestreamer.cpp +++ b/gui/nativestreamer.cpp @@ -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 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; }