QFileSystemModel/QFileSystemWatcher crashes

193 views
Skip to first unread message

Ralf Van Bogaert

unread,
Sep 30, 2011, 7:44:08 AM9/30/11
to lqt-bi...@googlegroups.com
Hi,

I'd like to make use of both the QFileSystemWatcher and QFileSystemModel classes.

However, this causes my program to crash frequently, whenever I add a path to the former or set a rootpath to the latter (which automatically creates a QFileSystemWatcher to work with)

Check out the following example;

package.cpath='/usr/lib/lua/5.1/?.so'
require 'qtcore'
require 'qtgui'
App,Window=QApplication.new(1,{'Test'}),QMainWindow.new_local()
local M=QFileSystemModel.new_local()
Window.Model=M
M:setRootPath(QDir.currentPath())
local V=QTreeView.new_local(Window)
Window.View=V
V:setModel(M)
Window:setCentralWidget(V)
Window:show()
App.exec()


This will crash four out of five times when run, with a variety of nonsensical error messages. Most of the time it just segfaults. When it doesn't crash, it works as intended.

Googling for more info;

https://bugreports.qt.nokia.com/browse/QTBUG-9249
http://web.archiveorange.com/archive/v/bZBuSkZANIyyRK4vR4dN

However I'm not sure these are related, since they specifially mention the Mac platform, and only whenever monitored files are being removed.

Regards,

Ralf

Michal Kottman

unread,
Oct 1, 2011, 4:57:45 PM10/1/11
to lqt-bi...@googlegroups.com
On Fri, 2011-09-30 at 13:44 +0200, Ralf Van Bogaert wrote:
> Hi,
>
> I'd like to make use of both the QFileSystemWatcher and
> QFileSystemModel classes.
>
> However, this causes my program to crash frequently, whenever I add a
> path to the former or set a rootpath to the latter (which
> automatically creates a QFileSystemWatcher to work with)
>
> Check out the following example;
>
> package.cpath='/usr/lib/lua/5.1/?.so'
> require 'qtcore'
> require 'qtgui'
> App,Window=QApplication.new(1,{'Test'}),QMainWindow.new_local()
> local M=QFileSystemModel.new_local()
> Window.Model=M
> M:setRootPath(QDir.currentPath())
> local V=QTreeView.new_local(Window)
> Window.View=V
> V:setModel(M)
> Window:setCentralWidget(V)
> Window:show()
> App.exec()
>
> This will crash four out of five times when run, with a variety of
> nonsensical error messages. Most of the time it just segfaults. When
> it doesn't crash, it works as intended.

I have been unable to find the bug. In the start, it worked for me, then
it suddenly started breaking at various unrelated places, then it
worked, then it started failing again. I have added a tracing option to
Lqt, and it seems that this problem is caused by the use of multiple
threads by Qt.

Lua is not ready to work with multiple threads accessing the same Lua
state. Unfortunately, the log shows that multiple thread are accessing
the same QApplication object (therefore accessing the same state),
leaving the possibility that they will crash the application.

I am trying various locking strategies, like locking the lqtL_* API and
objects using QMutex, but so far no luck. The only possibility seems to
be a GIL [1], but you have to modify Lua for that (it provides
lua_lock() and lua_unlock() macros). But this will mean that it will not
work with stock Lua if you use multiple threads (or use something that
uses multiple threads).

[1] http://en.wikipedia.org/wiki/Global_Interpreter_Lock


Ralf Van Bogaert

unread,
Oct 3, 2011, 6:28:26 AM10/3/11
to lqt-bi...@googlegroups.com
Hi,

Thanks for your time, I had the impression it was thread-related due to the similarity of the random errors when attempting to use QThread.

Regards

Ralf

Michal Kottman

unread,
Mar 11, 2012, 7:46:33 AM3/11/12
to lqt-bi...@googlegroups.com
As an update to the recent problems with Lqt and threading, I am now
looking at this example. I have place tracing calls EVERYWHERE in Lqt,
printing out the event type, function and thread id. I am using Qt 4.8
right now.

QFileSystemModel *works* for me right now, I can browse my computer on
Mac OSX, and it does not seem to use multiple threads from the logs.
However, I am getting this error for every program ran in Lqt:

lua(27567,0x7fff76dbe960) malloc: *** error for object 0x104cac380:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

I have no idea where this "bogus" object is coming from, since there
is only a single thread running, and it works fine during the run. I
suspect this is a problem of "double free". Unfortunately I am unable
to run a test in Valgrind, due to this:

vex amd64->IR: unhandled instruction bytes: 0x66 0xF 0x3A 0xDF 0xD1
0x1 0xE8 0x6A
==27572== valgrind: Unrecognised instruction at address 0xb4c0b.
==27572== at 0xB4C0B: aes_encrypt_key_hw (in
/usr/lib/system/libcommonCrypto.dylib)
==27572== by 0xB29E0: aesedp_setup (in /usr/lib/system/libcommonCrypto.dylib)
==27572== by 0xACBE3: cbc_start (in /usr/lib/system/libcommonCrypto.dylib)
==27572== by 0xAF5BB: CCCryptorCreateFromDataWithMode (in
/usr/lib/system/libcommonCrypto.dylib)
==27572== by 0xAF78D: CCCryptorCreateFromData (in
/usr/lib/system/libcommonCrypto.dylib)
==27572== by 0xAEDFC: CCCryptorCreate (in
/usr/lib/system/libcommonCrypto.dylib)
==27572== by 0xAFDC6: CCCrypt (in /usr/lib/system/libcommonCrypto.dylib)
==27572== by 0x4276463: -[NSPersistentUIManager init] (in
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==27572== by 0x4276350: __PersistentUIManager_block_invoke_1 (in
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==27572== by 0x596736A: _NSFaultInObject (in
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation)
==27572== by 0x42B607E: -[NSWindow(NSPersistentUISupport)
_invalidateRestorableStateOfContents] (in
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==27572== by 0x43C6066: -[NSWindow
_commonInitFrame:styleMask:backing:defer:] (in
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==27572== by 0x43C553A: -[NSWindow
_initContent:styleMask:backing:defer:contentView:] (in
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==27572== by 0x43C4F0A: -[NSWindow
initWithContentRect:styleMask:backing:defer:] (in
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==27572== by 0x2A82175: -[QCocoaWindow
initWithContentRect:styleMask:backing:defer:] (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2A82036: -[NSWindow(QWidgetIntegration)
qt_initWithQWidget:contentRect:styleMask:] (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2A74088: qt_mac_create_window(QWidget*, unsigned
int, unsigned long, QRect const&) (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2A73CB7: QWidgetPrivate::createWindow_sys() (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2A7313E: qt_mac_window_for(QWidget const*) (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2A79427: QWidgetPrivate::setModal_sys() (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2B1F9BD: QWidget::create(long, bool, bool) (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)
==27572== by 0x2B24695: QWidget::setVisible(bool) (in
/Library/Frameworks/QtGui.framework/Versions/4/QtGui)

It seems Lqt won't make it to upcoming Qt 5.0 if issues keep coming up... :(

Reply all
Reply to author
Forward
0 new messages