[Kwintv] V4L plugin crash solved...

Dirk Ziegelmeier dziegel at gmx.de
Sun Jan 4 01:21:13 CET 2004


I've been tracking down the crash in the V4L plugin I reported in one of my 
last mails. It's caused by the following problem (yes, the explanation is a 
bit lengthy, but it may be a good idea to have it archived in the ML archive 
for further reference):

QApplication deletes it's mainWidget when it is being deleted itself at the 
end of main(), _not_ when aQApplication.exec() returns. During the delete, it 
does not aquire the Qt Library Mutex. But the shutdown of the V4L grabber 
thread relies on a working Qt Library handshake.
So the following situation can happen: During the deletion, the grabber thread 
receives it's stop signal (member _stop is set to true) and the object 
deletion continues, deleting the TV screen and the V4LGrabber instance. 
Somewhere in the meantime, the thread wakes up, aquires the Qt Lib Mutex 
since it is not locked and starts to paint to a deleted widget using the 
deleted _image buffer...

Below is a (lengthy) debug log I used to find it.

I solved it by connecting qApp->aboutToQuit() to QtVisionV4L::stopVideo(). 
This makes sure the stop event is delivered whil the Qt Lib Mutex handshake 
is still operational. I restarted and shut down the App about 30 times 
without a crash now, so I hope this really fixes it.

I also changed the _stopSem to a simple boolean var, since there is only one 
writer and one reader thread, and the reader only tests for 0 or not 0. So a 
semaphore is not necessary here.

Also, the usleep() delay Koos introduced in main() is not necessary any more.

Ciao,
Dirk


V4L Debug log:
----

lock devMtx
devMtx locked
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
unlocking qApp
qApp unlocked
lock devMtx
devMtx locked
*************** Mainloop terminated.
qtvision: SaverControl: KDE screensaver successfully enabled.
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
unlocking qApp
qApp unlocked
lock devMtx
devMtx locked
qtvision: MainWindow::setShowNormal(): false
qtvision: MainWindow::setShowNormal(): true
qtvision: SaverControl: KDE screensaver successfully enabled.
qtvision: ChannelIO::save(...) 
file='/home/dziegel/.kde/share/apps/qtvision/channels.xml' format='xml'
qtvision: ChannelIO::findFormat(...) xml, flags=2
qtvision: ChannelIO::findFormat(...) io XML Channel Plugin can write xml
qtvision: ChannelIO::save(...) using format 'XML Channel Plugin'
qtvision: IOFormatXML::save(...)
qtvision: QVChannelPlugin::save(...) sub-class save ok
qtvision: ALSA Mixer Plugin: [setMuted()] Line on hw:0 muted=true
qtvision: QtVision::setMuteVolume(): Mixer says volume is Muted
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
unlocking qApp
qApp unlocked
lock devMtx
devMtx locked
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
unlocking qApp
qApp unlocked
lock devMtx
qtvision: QtVision::setMuteVolume(): Tuner says volume is Muted
qtvision: CfgData: Saving settings for device: BT878(Hauppauge WinTV PVR) 
Video4Linux(/dev/video1)
devMtx locked
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
unlocking qApp
qApp unlocked
lock devMtx
devMtx locked
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
unlocking qApp
qApp unlocked
lock devMtx
devMtx locked
unlocking devMtx
devMtx unlocked
lock qApp
qApp locked
qtvision: CfgData: Saving picture settings for device: BT878(Hauppauge WinTV 
PVR) Video4Linux(/dev/video1) with key: television
qtvision: Sourcemanager: stopDevice()
qtvision: Sourcemanager: stopVideo()
V4LGrabber::stop().
qtvision: PluginFactory: putPlugin(): 'Video4Linux Plugin' refCount: 0
qtvision: KXv: Close Xv connection.
qtvision: CfgData: save()
qtvision: PluginFactory: putPlugin(): 'Teletext Plugin' refCount: 0
qtvision: PluginFactory: putPlugin(): 'libZVBI VBI Decoder Plugin' refCount: 0
qtvision: PluginFactory: putPlugin(): 'Station Info Plugin' refCount: 0
qtvision: PluginFactory: putPlugin(): 'Elegant On-screen Display Plugin' 
refCount: 0
qtvision: Elegant: destroying plugin.


[New Thread 16384 (LWP 3006)]
[New Thread 32769 (LWP 3030)]
[New Thread 16386 (LWP 3031)]
0x41b20d2a in waitpid () from /lib/libpthread.so.0
#0  0x41b20d2a in waitpid () from /lib/libpthread.so.0
#1  0x40ee82ea in KCrash::defaultCrashHandler(int) ()
   from /opt/kde3/lib/libkdecore.so.4
#2  0x41b1f895 in __pthread_sighandler () from /lib/libpthread.so.0
#3  <signal handler called>
#4  0x41cc3b4f in memcpy () from /lib/libc.so.6
#5  0x082b3598 in ?? ()
#6  0x42595fff in KXvDevice::displayImage(QWidget*, unsigned char const*, int, 
int, int, int) (this=0x82b3598, widget=0x0, 
    data=0x427c9000 <Address 0x427c9000 out of bounds>, w=680, h=512, dw=683, 
    dh=512) at /usr/lib/qt3/include/qwidget.h:712
#7  0x4259a917 in QVideoStream::displayFrame(unsigned char const*) (
    this=0xbf7ff3f0, img=0xbf7ff36c "tó\177¿/ø±A")
    at /usr/lib/qt3/include/qsize.h:132
#8  0x4259aad1 in QVideoStream::operator<<(unsigned char const*) (
    this=0x82b14c8, img=0x427c9000 <Address 0x427c9000 out of bounds>)
    at qvideostream.cpp:442
#9  0x42586458 in QtVisionV4L::event(QEvent*) (this=0x82b14c8, e=0xbf7ffa7c)
    at qtvision_v4l.cpp:912
#10 0x412816ef in QApplication::internalNotify(QObject*, QEvent*) ()
   from /usr/lib/qt3/lib/libqt-mt.so.3
#11 0x412809a0 in QApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/qt3/lib/libqt-mt.so.3
#12 0x40e79a8f in KApplication::notify(QObject*, QEvent*) ()
   from /opt/kde3/lib/libkdecore.so.4
#13 0x42581918 in V4LGrabber::run() (this=0x82b6ee0) at qtvision_v4l.cpp:206
#14 0x41272565 in QThreadInstance::start(void*) ()
   from /usr/lib/qt3/lib/libqt-mt.so.3
#15 0x41b19c60 in pthread_start_thread () from /lib/libpthread.so.0


More information about the kwintv mailing list