Bug 445276

Summary: krita segfaults on start after displaying the splash screen when a whole log of packages are disabled
Product: [Applications] krita Reporter: Timo Gurr <timo.gurr>
Component: GeneralAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: halla
Priority: NOR    
Version: 4.4.8   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: coredump.txt

Description Timo Gurr 2021-11-10 12:47:03 UTC
Created attachment 143410 [details]
coredump.txt

SUMMARY
Krita crashes right on start just after displaying the splash screen.

STEPS TO REPRODUCE
1.  Compile Krita 4.4.8
2.  Try to run it

OBSERVED RESULT
Segfault

EXPECTED RESULT
No segfault

SOFTWARE/OS VERSIONS
Operating System: Exherbo
KDE Plasma Version: 5.23.2
KDE Frameworks Version: 5.87.0
Qt Version: 5.15.2 (qtbase kde/5.15 branch fixes up to 5.15.2_p254)
Kernel Version: 5.15.1 (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Core™ i5-6500 CPU @ 3.20GHz
Memory: 11.5 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 530

ADDITIONAL INFORMATION
Used CMake options during build:

cmake -DCMAKE_COLOR_MAKEFILE:BOOL=TRUE -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=None -DCMAKE_C_FLAGS:STRING=-march=native -O2 -pipe -DCMAKE_CXX_FLAGS:STRING=-march=native -O2 -pipe -DCMAKE_AR:PATH=x86_64-pc-linux-gnu-ar -DCMAKE_RANLIB:PATH=x86_64-pc-linux-gnu-ranlib -DCMAKE_NM:PATH=x86_64-pc-linux-gnu-nm -DCMAKE_C_COMPILER:PATH=x86_64-pc-linux-gnu-cc -DCMAKE_CXX_COMPILER:PATH=x86_64-pc-linux-gnu-c++ -DCMAKE_INSTALL_PREFIX:PATH=/usr/x86_64-pc-linux-gnu -DCMAKE_FIND_ROOT_PATH=/usr/x86_64-pc-linux-gnu -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM:STRING=NEVER -DCMAKE_SYSTEM_PREFIX_PATH:PATH=/usr/x86_64-pc-linux-gnu -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_DATAROOTDIR:PATH=/usr/share/ -DBUILD_COVERAGE:BOOL=FALSE -DBUILD_KRITA_QT_DESIGNER_PLUGINS:BOOL=FALSE -DCMAKE_DISABLE_FIND_PACKAGE_KSeExpr:BOOL=TRUE -DCRASH_ON_SAFE_ASSERTS:BOOL=FALSE -DENABLE_CPU_THROTTLE:BOOL=FALSE -DHAVE_BACKTRACE_SUPPORT:BOOL=FALSE -DHAVE_MEMORY_LEAK_TRACKER:BOOL=FALSE -DHIDE_SAFE_ASSERTS:BOOL=TRUE -DKRITA_ENABLE_BROKEN_TESTS:BOOL=FALSE -DLIMIT_LONG_TESTS:BOOL=TRUE -DSHARED_LIBS:BOOL=TRUE -DUSE_LOCK_FREE_HASH_TABLE:BOOL=TRUE -DFOUNDATION_BUILD:BOOL=FALSE -DENABLE_PYTHON_2:BOOL=FALSE -DKRITA_DEVS:BOOL=FALSE -DBUILD_SHARED_LIBS:BOOL=TRUE -DKDE_INSTALL_AUTOSTARTDIR=/etc/xdg/autostart -DKDE_INSTALL_CONFDIR=/etc/xdg -DKDE_INSTALL_DATAROOTDIR:PATH=/usr/share -DKDE_INSTALL_LIBEXECDIR=libexec -DKDE_INSTALL_SYSCONFDIR=/etc -DKDE_INSTALL_USE_QT_SYS_PATHS:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_FFTW3:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_OpenColorIO:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_HEIF:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_OpenJPEG:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_OpenEXR:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_Poppler:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_PythonInterp:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_PythonLibrary:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_SIP:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_PyQt5:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_LibRaw:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Multimedia:BOOL=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_TIFF:BOOL=FALSE -DCMAKE_DISABLE_FIND_PACKAGE_Vc:BOOL=TRUE -DBUILD_TESTING:BOOL=FALSE /var/tmp/paludis/build/media-gfx-krita-4.4.8/work/krita-4.4.8

Attached you'll find, the hopefully useful, coredump.

Kcrash Handler Output Krita 4.4.8:
Application: krita (krita), signal: Segmentation fault
[KCrash Handler]
#4  0x00007feeda679a98 in KisVisualColorSelector::slotSetColorSpace(KoColorSpace const*) () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.20
#5  0x00007feeda6777a0 in KisVisualColorSelector::slotSetColor(KoColor const&) () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.20
#6  0x00007feeda680629 in KisDlgInternalColorSelector::KisDlgInternalColorSelector(QWidget*, KoColor, KisDlgInternalColorSelector::Config, QString const&, KoColorDisplayRendererInterface const*) () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.20
#7  0x00007feedd9d5376 in KoDualColorButton::Private::init(KoDualColorButton*) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#8  0x00007feedd9d778c in KoDualColorButton::KoDualColorButton(KoColor const&, KoColor const&, KoColorDisplayRendererInterface const*, QWidget*, QWidget*) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#9  0x00007feedd80a4d7 in KisControlFrame::setup(QWidget*) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#10 0x00007feeddaede39 in KisViewManager::KisViewManager(QWidget*, KActionCollection*) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#11 0x00007feeddabdaee in KisMainWindow::KisMainWindow(QUuid) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#12 0x00007feeddac9257 in KisPart::createMainWindow(QUuid) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#13 0x00007feeddac9bda in KisPart::startBlankSession() () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#14 0x00007feedda855df in KisApplication::start(KisApplicationArguments const&) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.20
#15 0x0000565512ee39db in main ()
[Inferior 1 (process 7976) detached]

The older Krita 4.2.9 compiled on the same system does not segfault.

Krita Git master as of today crashes as well with a (slightly) different output.

Kcrash Handler Output Krita Git master - 2e0fde23844bdd8c045cde99431010093612befc:
Application: krita (krita), signal: Segmentation fault
[KCrash Handler]
#4  0x00007f0195ab7271 in KoColor::toSVG11(QHash<QString, KoColorProfile const*>*) const () from /usr/x86_64-pc-linux-gnu/lib/libkritapigment.so.18
#5  0x00007f0195c63231 in KoStopGradient::saveSvgGradient() const () from /usr/x86_64-pc-linux-gnu/lib/libkritapigment.so.18
#6  0x00007f0195c68759 in KoStopGradient::saveToDevice(QIODevice*) const () from /usr/x86_64-pc-linux-gnu/lib/libkritapigment.so.18
#7  0x00007f0197d2252c in KisMemoryStorage::addResource(QString const&, QSharedPointer<KoResource>) () from /usr/x86_64-pc-linux-gnu/lib/libkritaresources.so.18
#8  0x00007f0197cf66a8 in KisResourceStorage::addResource(QSharedPointer<KoResource>) () from /usr/x86_64-pc-linux-gnu/lib/libkritaresources.so.18
#9  0x00007f0197ceb800 in KisResourceLocator::addResource(QString const&, QSharedPointer<KoResource>, QString const&) () from /usr/x86_64-pc-linux-gnu/lib/libkritaresources.so.18
#10 0x00007f0197d02592 in KisAllResourcesModel::addResource(QSharedPointer<KoResource>, QString const&) () from /usr/x86_64-pc-linux-gnu/lib/libkritaresources.so.18
#11 0x00007f0197cffcfe in KisResourceModel::addResource(QSharedPointer<KoResource>, QString const&) () from /usr/x86_64-pc-linux-gnu/lib/libkritaresources.so.18
#12 0x00007f01960bc074 in KoResourceServer<KoAbstractGradient>::addResource(QSharedPointer<KoAbstractGradient>, bool) [clone .isra.0] () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.18
#13 0x00007f01960bc844 in GradientResourceServer::insertSpecialGradients() () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.18
#14 0x00007f01960b975f in KoResourceServerProvider::KoResourceServerProvider() () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.18
#15 0x00007f01960b9887 in KoResourceServerProvider::instance() () from /usr/x86_64-pc-linux-gnu/lib/libkritawidgets.so.18
#16 0x00007f01989577ae in KisPart::KisPart() () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.18
#17 0x00007f01989579a7 in KisPart::instance() () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.18
#18 0x00007f019890a145 in KisApplication::start(KisApplicationArguments const&) () from /usr/x86_64-pc-linux-gnu/lib/libkritaui.so.18
#19 0x000055b81fe16a8e in main ()
[Inferior 1 (process 26608) detached]
Comment 1 Halla Rempt 2021-11-10 12:52:48 UTC
It would be better to build without so many packages disabled... You're definitely going to run into trouble. I suspect that this patch will fix the issue, but I am not going to create a build like yours to test this out:

diff --git a/libs/widgets/KisVisualColorSelector.cpp b/libs/widgets/KisVisualColorSelector.cpp
index 8cb62bc2fb..c2f5c5689d 100644
--- a/libs/widgets/KisVisualColorSelector.cpp
+++ b/libs/widgets/KisVisualColorSelector.cpp
@@ -94,8 +94,9 @@ void KisVisualColorSelector::slotSetColorSpace(const KoColorSpace *cs)
         const KoColorSpace *csNew = cs;
 
         // PQ color space is not very suitable for selecting colors, substitute with linear one
-        if (cs->colorModelId() == RGBAColorModelID &&
-            cs->profile()->uniqueId() == KoColorSpaceRegistry::instance()->p2020PQProfile()->uniqueId()) {
+        if (cs->colorModelId() == RGBAColorModelID
+                && KoColorSpaceRegistry::instance()->p2020PQProfile() &&
+                cs->profile()->uniqueId() == KoColorSpaceRegistry::instance()->p2020PQProfile()->uniqueId()) {
 
             csNew = KoColorSpaceRegistry::instance()->
                     colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(),

Please check whether this works.
Comment 2 Timo Gurr 2021-11-10 14:09:21 UTC
(In reply to Halla Rempt from comment #1)
> It would be better to build without so many packages disabled... You're
> definitely going to run into trouble. I suspect that this patch will fix the
> issue, but I am not going to create a build like yours to test this out:
> 
> diff --git a/libs/widgets/KisVisualColorSelector.cpp
> b/libs/widgets/KisVisualColorSelector.cpp
> index 8cb62bc2fb..c2f5c5689d 100644
> --- a/libs/widgets/KisVisualColorSelector.cpp
> +++ b/libs/widgets/KisVisualColorSelector.cpp
> @@ -94,8 +94,9 @@ void KisVisualColorSelector::slotSetColorSpace(const
> KoColorSpace *cs)
>          const KoColorSpace *csNew = cs;
>  
>          // PQ color space is not very suitable for selecting colors,
> substitute with linear one
> -        if (cs->colorModelId() == RGBAColorModelID &&
> -            cs->profile()->uniqueId() ==
> KoColorSpaceRegistry::instance()->p2020PQProfile()->uniqueId()) {
> +        if (cs->colorModelId() == RGBAColorModelID
> +                && KoColorSpaceRegistry::instance()->p2020PQProfile() &&
> +                cs->profile()->uniqueId() ==
> KoColorSpaceRegistry::instance()->p2020PQProfile()->uniqueId()) {
>  
>              csNew = KoColorSpaceRegistry::instance()->
>                      colorSpace(RGBAColorModelID.id(),
> Float32BitsColorDepthID.id(),
> 
> Please check whether this works.

Thanks for the immediate nearly instant help, you're awesome! Sorry that I couldn't get back to you as fast as you came up with the patch, Krita takes a while to compile on my machine(s). I can confirm that the patch you've provided fixes the issue.

I disabled as much as I could for testing purposes, however as Exherbo is a source-based distribution like Gentoo we offer a few options to enable/disable optional features on compile-time.
Comment 3 Halla Rempt 2021-11-10 14:52:02 UTC
Cool, I'll push the patch.
Comment 4 Halla Rempt 2021-11-10 14:52:57 UTC
Git commit 17a3a4c25ff686aec09033bac12d04e43ca03cbd by Halla Rempt.
Committed on 10/11/2021 at 14:52.
Pushed by rempt into branch 'master'.

Check pointers before derefencing.

This fixes a crash on startup if a whole lotta optional deps are
disabled.

M  +5    -3    libs/widgets/KisVisualColorSelector.cpp

https://invent.kde.org/graphics/krita/commit/17a3a4c25ff686aec09033bac12d04e43ca03cbd
Comment 5 Halla Rempt 2021-11-10 14:53:22 UTC
Git commit 2dda4236f9fcf45b3bb4d1c45330d42d870fdea5 by Halla Rempt.
Committed on 10/11/2021 at 14:53.
Pushed by rempt into branch 'krita/5.0'.

Check pointers before derefencing.

This fixes a crash on startup if a whole lotta optional deps are
disabled.
(cherry picked from commit ce2138f009e82c5363ff5dfdd758d69a35676881)

M  +5    -3    libs/widgets/KisVisualColorSelector.cpp

https://invent.kde.org/graphics/krita/commit/2dda4236f9fcf45b3bb4d1c45330d42d870fdea5