You must not destroy a QThread that is running (see the QT book by trolltech).
Send the QThread object a signal that makes it's main loop exit, then wait
for the thread, then destroy it.
pseude code (not tested):
class MyThread: public QThread
{
slots:
void cancel();
private:
bool cancelled;
QMutex cancelAccess;
}
MyThread::cancel()
{
QMutexLocker lock(&cancelAccess);
cancelled = true;
}
MyThread::run()
{
...init thread stuff...
while(loop condition)
{
...do something...
{
QMutexLocker lock(&cancelAccess)
if (cancelled)
{
...clean up loop-internal stuff...
break;
}
}
}
...clean up thread stuff...
}
function on_cancelButton_clicked()
{
theThread->cancel();
theThread->wait();
delete theThread;
theThread=NULL;
}
Josiah Bryan schrieb:
> Hey All -
>
> I'm using Qt 4.5 and doing video decoding inside a QThread. When the
> thread is destroyed, it goes through and frees up the libav* stuff its
> allocated. One of the calls to av_free() in particular is causing a
> SIGSEGV - with that call in, program SIGSEGV's, with that call commented
> out, no sigsegv.
>
> av_free(m_av_frame);
>
> The odd thing is, right before I free m_av_frame(), I also use av_free()
> on two other libav* structs.
>
> m_av_frame is just allocated like this:
>
> m_av_frame = avcodec_alloc_frame();
>
> This is the frame that is given to avcodec_deocde_video(), then I
> convert it to RGB32 using sws_scale() - so the data is completely
> internal to the thread.
>
> I've even tried wrapping the calls to av_free in a mutex - still sigsegvs.
>
> To troubleshoot, I've tried gdb (only a single line stack trace on
> sigsegv, location is "??" according to gdb.) I can't get valgrind's
> helgrind tool working on my system, and I'm plum out of ideas on how to
> troubleshoot this.
>
> Any else have any ideas on how to troubleshoot?
>
> Thanks!
> -josiah
>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user