Bug 386279

Summary: Random crash in KisUpdateJobItem
Product: [Applications] krita Reporter: Bernhard Liebl <poke1024>
Component: GeneralAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: halla
Priority: NOR    
Version First Reported In: 4.0 pre-alpha   
Target Milestone: ---   
Platform: Compiled Sources   
OS: macOS   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: same thing again

Description Bernhard Liebl 2017-10-28 10:32:31 UTC
Happened with c6473821e095b6b4462259ab119265423de80c8d

The access looks like a nullptr memory exception (KERN_INVALID_ADDRESS at 0x0000000000000038).

So it seems like it's inside KisUpdateJobItem::runMergeJob (inlined) and then gets a nullptr memory exception when accessing m_walker->changeRect() as m_walker is null.
Comment 1 Bernhard Liebl 2017-10-28 10:34:20 UTC
Oh, I just detected some more info from the console:

krita.core: BUG: The walker hasn't reached the root layer!
krita.core:      Start node: KisPaintLayer(0x7fa5c4bde050, name = "Layer 2") Requested rect: QRect(7929953,7471205 -4653120x-4784194)
krita.core:      There must be an inconsistency in the walkers happened!
krita.core:      Please report a bug describing how you got this message.
Segmentation fault: 11
Comment 2 Bernhard Liebl 2017-10-28 10:46:36 UTC
Created attachment 108602 [details]
same thing again
Comment 3 Halla Rempt 2017-11-08 13:07:54 UTC
Something like this should solve it:

diff --git a/libs/image/kis_async_merger.cpp b/libs/image/kis_async_merger.cpp
index 041f6fbc68..9739eefab5 100644
--- a/libs/image/kis_async_merger.cpp
+++ b/libs/image/kis_async_merger.cpp
@@ -290,7 +290,6 @@ void KisAsyncMerger::startMerge(KisBaseRectsWalker &walker, bool notifyClones) {
     if(m_currentProjection) {
         warnImage << "BUG: The walker hasn't reached the root layer!";
         warnImage << "     Start node:" << walker.startNode() << "Requested rect:" << walker.requestedRect();
-        warnImage << "     There must be an inconsistency in the walkers happened!";
         warnImage << "     Please report a bug describing how you got this message.";
         // reset projection to avoid artefacts in next merges and allow people to work further
         resetProjection();
diff --git a/libs/image/kis_update_job_item.h b/libs/image/kis_update_job_item.h
index 3ac09e3436..6987611bba 100644
--- a/libs/image/kis_update_job_item.h
+++ b/libs/image/kis_update_job_item.h
@@ -100,7 +100,7 @@ public:
 
             m_exclusiveJobLock->unlock();
 
-            // try to exit the loop. Please note, that noone can flip the state from
+            // try to exit the loop. Please note, that no-one can flip the state from
             // WAITING to EMPTY except ourselves!
             Type expectedValue = Type::WAITING;
             if (m_atomicType.compare_exchange_strong(expectedValue, Type::EMPTY)) {
@@ -111,6 +111,11 @@ public:
 
     inline void runMergeJob() {
         Q_ASSERT(m_atomicType == Type::MERGE);
+        if (!m_walker) {
+            qWarning() << "KisUpdateJobItem::runMergeJob: we have an invalid walker.";
+            return;
+        }
+
         // dbgKrita << "Executing merge job" << m_walker->changeRect()
         //          << "on thread" << QThread::currentThreadId();
         m_merger.startMerge(*m_walker);
Comment 4 Halla Rempt 2017-11-21 13:48:22 UTC
Looks like a duplicate of 380246

*** This bug has been marked as a duplicate of bug 380246 ***
Comment 5 Halla Rempt 2017-11-26 13:27:47 UTC
No, this is not a true duplicate, because the other bug actually was about an assert in KoDerivedResourceConverter: 

    KIS_SAFE_ASSERT_RECOVER_NOOP(m_d->lastKnownValue.isNull() ||
                                 result == m_d->lastKnownValue);
Comment 6 Halla Rempt 2017-11-26 13:29:38 UTC
Git commit a20c53eea0c1548502b78a73879488a09a27844c by Boudewijn Rempt.
Committed on 26/11/2017 at 13:29.
Pushed by rempt into branch 'master'.

Add safe assert checking for the walker in KisUpdateJobItem

M  +2    -1    libs/image/kis_update_job_item.h

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