Bug 376993 - After converting a file layer to a paint layer, when the undo stack clears the file layer and deletes it, QFileSystemWatcher crashes because that happens in a different thread.
Summary: After converting a file layer to a paint layer, when the undo stack clears th...
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Layer Stack (show other bugs)
Version: 3.1.2
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-27 22:30 UTC by Manga Tengu
Modified: 2017-02-28 14:24 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Terminal's output during a crash (3.20 KB, text/plain)
2017-02-27 22:30 UTC, Manga Tengu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Manga Tengu 2017-02-27 22:30:19 UTC
Created attachment 104251 [details]
Terminal's output during a crash

When I convert a file layer to paint layer, then paint without closing the file between conversion and painting, after 50-60 strokes (brush around 110px wide on an A3 300dpi), krita crashes systematically (it closes in the blink of an eye).

If I paint over a file where I did the conversion but closed krita between conversion and painting, it will work fine.

I tried to get a hint (maybe it's my machine ?...) so I launched via terminal and logged krita's output in a txt file I attached.
Comment 1 Halla Rempt 2017-02-28 13:01:30 UTC
Hi!

I can reproduce it easily:


Thread 1 "krita" received signal SIGSEGV, Segmentation fault.
0x00007fffee0dc70f in QSocketNotifier::setEnabled(bool) () from /home/boud/dev/deps/lib/libQt5Core.so.5
Missing separate debuginfos, use: zypper install libICE6-debuginfo-1.0.9-3.1.x86_64 libSM6-debuginfo-1.2.2-5.1.x86_64 libX11-6-debuginfo-1.6.3-9.1.x86_64 libX11-xcb1-debuginfo-1.6.3-9.1.x86_64 libXau6-debuginfo-1.0.8-6.1.x86_64 libXcursor1-debuginfo-1.1.14-6.1.x86_64 libXext6-debuginfo-1.3.3-3.1.x86_64 libXfixes3-debuginfo-5.0.1-7.1.x86_64 libXi6-debuginfo-1.7.5-6.1.x86_64 libXrender1-debuginfo-0.9.9-3.1.x86_64 libbz2-1-debuginfo-1.0.6-32.1.x86_64 libdbus-1-3-debuginfo-1.8.22-10.1.x86_64 libffi4-debuginfo-5.3.1+r233831-6.1.x86_64 libfreetype6-debuginfo-2.5.5-8.2.x86_64 libgcc_s1-debuginfo-5.3.1+r233831-6.1.x86_64 libglib-2_0-0-debuginfo-2.44.1-2.3.x86_64 libgobject-2_0-0-debuginfo-2.44.1-2.3.x86_64 libgomp1-debuginfo-5.3.1+r233831-6.1.x86_64 libgthread-2_0-0-debuginfo-2.44.1-2.3.x86_64 libicu52_1-debuginfo-52.1-10.3.x86_64 liblzma5-debuginfo-5.0.5-3.5.x86_64 libpcre1-debuginfo-8.39-5.1.x86_64 libstdc++6-debuginfo-5.3.1+r233831-6.1.x86_64 libuuid1-debuginfo-2.25-18.1.x86_64 libwayland-client0-debuginfo-1.12.0-3.1.x86_64 libwayland-server0-debuginfo-1.12.0-3.1.x86_64 libxcb-keysyms1-debuginfo-0.4.0-1.1.x86_64 libxcb-util1-debuginfo-0.4.0-1.1.x86_64 libxcb1-debuginfo-1.11.1-1.1.x86_64
(gdb) bt
#0  0x00007fffee0dc70f in QSocketNotifier::setEnabled(bool) () at /home/boud/dev/deps/lib/libQt5Core.so.5
#1  0x00007fffee0f5c30 in  () at /home/boud/dev/deps/lib/libQt5Core.so.5
#2  0x00007fffeaee58f1 in g_main_context_check () at /usr/lib64/libglib-2.0.so.0
#3  0x00007fffeaee5df8 in  () at /usr/lib64/libglib-2.0.so.0
#4  0x00007fffeaee5f7c in g_main_context_iteration () at /usr/lib64/libglib-2.0.so.0
#5  0x00007fffee0f5d7b in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
    at /home/boud/dev/deps/lib/libQt5Core.so.5
#6  0x00007fffee0a3a8b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
    at /home/boud/dev/deps/lib/libQt5Core.so.5
#7  0x00007fffee0ab7c6 in QCoreApplication::exec() () at /home/boud/dev/deps/lib/libQt5Core.so.5
#8  0x0000000000405781 in main(int, char**) (argc=1, argv=<optimized out>)
    at /home/boud/dev/krita/krita/main.cc:263
(gdb)
Comment 2 Halla Rempt 2017-02-28 13:02:26 UTC
I suspect the thingie that keeps checking the original file for changes is still running after the conversion, and goes haywire. Which also explains why this doesn't happen after save/close/reload.
Comment 3 Halla Rempt 2017-02-28 13:55:33 UTC
Creating KisSafeDocumentLoader KisSafeDocumentLoader(0x9699228)
creasting file layer KisFileLayer(0x96991d0, name = "Layer 3")
delet6ing file layer KisFileLayer(0x96991d0, name = "Layer 3")
Deleting KisSafeDocumentLoader KisSafeDocumentLoader(0x9699228)
QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread
QSocketNotifier: Invalid socket 41 and type 'Read', disabling...
Segmentation fault
Comment 4 Halla Rempt 2017-02-28 14:03:38 UTC
What needs to be done here is:

* Make the QFileSystemWatcher used in KisSafeDocumentLoader a global static instance, created in the main thread.
* Use that single instance for all file layers
* Make sure that the fileChangedCompressed passes the changed path so we can compare it to the one for this file layer, and only react on that.
Comment 5 Halla Rempt 2017-02-28 14:24:05 UTC
Git commit dbdf2f2a42b6db2a5d8415bbf9eb21a6a21a0da8 by Boudewijn Rempt.
Committed on 28/02/2017 at 14:22.
Pushed by rempt into branch 'master'.

QFileSystemWatcher cannot be deleted in a different thread from
where it was created. That did happen when a file layer was deleted
after converting it to a paint layer when the undo command was
pushed off the stack.

This change creates a single static QFileSystemWatcher that all
file layers connect to. fileChanged checks that the changed file
is the right one before setting the fileChanged flag.

M  +16   -11   libs/ui/kis_safe_document_loader.cpp
M  +1    -2    libs/ui/kis_safe_document_loader.h

https://commits.kde.org/krita/dbdf2f2a42b6db2a5d8415bbf9eb21a6a21a0da8
Comment 6 Halla Rempt 2017-02-28 14:24:14 UTC
Git commit f70b9905f5d7b31563452970c5cbae9995dbdbfd by Boudewijn Rempt.
Committed on 28/02/2017 at 14:24.
Pushed by rempt into branch 'krita/3.1'.

QFileSystemWatcher cannot be deleted in a different thread from
where it was created. That did happen when a file layer was deleted
after converting it to a paint layer when the undo command was
pushed off the stack.

This change creates a single static QFileSystemWatcher that all
file layers connect to. fileChanged checks that the changed file
is the right one before setting the fileChanged flag.

M  +16   -11   libs/ui/kis_safe_document_loader.cpp
M  +1    -2    libs/ui/kis_safe_document_loader.h

https://commits.kde.org/krita/f70b9905f5d7b31563452970c5cbae9995dbdbfd