Bug 383481

Summary: Segfault when creating document with two windows opened
Product: [Applications] krita Reporter: Nicholas LaPointe <nicholaslapointe8>
Component: GeneralAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: halla
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Backtrace

Description Nicholas LaPointe 2017-08-14 09:46:32 UTC
Created attachment 107272 [details]
Backtrace

1. Start Krita
2. "Window" -> "New Window"
3. Create new document
Krita will receive a segmentation fault.

This started with:
commit 769fdd467fc66f408410f8b6e1ead8d04dc51432
Author: Dmitry Kazakov
Date:   Tue Jul 25 18:44:47 2017 +0300

    Fix correct set up of the Canvas Switcher
    
    The canvas switcher should be connected to the canvases of its
    own main windows, not to all the canvases. It causes double delivery
    of some events (Focus, Mouse Press) to a wrong target. Sometimes it
    can also cause hangups


(As an aside, I'm curious about this commit:
The message mentions hangups, and I may recall being lead to one of the files it touched when I looked into bug 374496
The unfixed "hang" part of that bug is why I reopened bug 364984 (although I probably should have reopened the other one in retrospect.)

If the commit does indeed fix the hang, then bug 364984 can be closed.)
Comment 1 Halla Rempt 2017-08-14 11:31:20 UTC
Hm... I cannot reproduce the issue.
Comment 2 Halla Rempt 2017-08-14 11:34:45 UTC
In any case, accessing a pointer without checking it is wrong, so we could probably "fix" the issue with this patch:

diff --git a/libs/ui/input/kis_input_manager.cpp b/libs/ui/input/kis_input_manager.cpp
index 6faf5c5574..a2fc48d0cc 100644
--- a/libs/ui/input/kis_input_manager.cpp
+++ b/libs/ui/input/kis_input_manager.cpp
@@ -556,10 +556,12 @@ void KisInputManager::slotToolChanged()
 {
     KoToolManager *toolManager = KoToolManager::instance();
     KoToolBase *tool = toolManager->toolById(canvas(), toolManager->activeToolId());
-    d->setMaskSyntheticEvents(tool->maskSyntheticEvents());
-    if (tool && tool->isInTextMode()) {
-        d->forwardAllEventsToTool = true;
-        d->matcher.suppressAllActions(true);
+    if (tool) {
+        d->setMaskSyntheticEvents(tool->maskSyntheticEvents());
+        if (tool->isInTextMode()) {
+            d->forwardAllEventsToTool = true;
+            d->matcher.suppressAllActions(true);
+        }
     } else {
         d->forwardAllEventsToTool = false;
         d->matcher.suppressAllActions(false);
Comment 3 Halla Rempt 2017-08-14 11:53:39 UTC
Hm, I managed to get a crash but only by opening three windows and then opening a new view on a document, not a new window.
Comment 4 Halla Rempt 2017-08-15 07:35:09 UTC
Git commit 1736dd852ace5ec81a2131351b75ba42984fcb99 by Boudewijn Rempt.
Committed on 15/08/2017 at 07:33.
Pushed by rempt into branch 'krita/3.2'.

M  +10   -7    libs/ui/input/kis_input_manager.cpp

https://commits.kde.org/krita/1736dd852ace5ec81a2131351b75ba42984fcb99
Comment 5 Halla Rempt 2017-08-15 07:35:23 UTC
Git commit f566a8023cba382e4fc7f866b494684964cf7be7 by Boudewijn Rempt.
Committed on 15/08/2017 at 07:35.
Pushed by rempt into branch 'master'.

M  +10   -7    libs/ui/input/kis_input_manager.cpp

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