Bug 404080 - Logarithmic blend modes causes floating point exception (core dumped)
Summary: Logarithmic blend modes causes floating point exception (core dumped)
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: General (show other bugs)
Version: nightly build (please specify the git hash!)
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: reptillia39
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-08 06:52 UTC by M
Modified: 2019-02-23 14:39 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
What the Burn Blend Mode should look like (89.57 KB, image/png)
2019-02-17 01:50 UTC, reptillia39
Details

Note You need to log in before you can comment on or make changes to this bug.
Description M 2019-02-08 06:52:43 UTC
I tried the new blending modes added in the appimage from 07. Feb.

Selecting "Color Dodge - Logarithmic" always results in Krita locking up and exiting with a floating point exception (core dumped). Setting a layer to this blending mode locks immediately, using it on a brush locks as soon as it touches the canvas. I tried both RGB and LAB color spaces with both internal and dedicated GPU on my laptop (through primusrun) - same outcome every time.

  Version: 4.2.0-pre-alpha (git b8d64d3)

Qt

  Version (compiled): 5.10.0
  Version (loaded): 5.10.0

OS Information

  Build ABI: x86_64-little_endian-lp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: linux
  Kernel Version: 4.20.7-1-MANJARO
  Pretty Productname: Manjaro Linux
  Product Type: manjaro
  Product Version: unknown

OpenGL Info
 
  Vendor:  NVIDIA Corporation 
  Renderer:  "GeForce GTX 860M/PCIe/SSE2" 
  Version:  "4.6.0 NVIDIA 415.27" 
  Shading language:  4.60 NVIDIA 
  Requested format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 0, colorSpace QSurfaceFormat::ColorSpace(DefaultColorSpace), profile  QSurfaceFormat::OpenGLContextProfile(CompatibilityProfile)) 
  Current format:    QSurfaceFormat(version 4.6, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 0, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 0, colorSpace QSurfaceFormat::ColorSpace(DefaultColorSpace), profile  QSurfaceFormat::OpenGLContextProfile(CompatibilityProfile)) 
     Version: 4.6
     Supports deprecated functions true 
     is OpenGL ES: false 

Hardware Information

  GPU Acceleration: auto
  Memory: 15951 Mb
  Number of Cores: 8
  Swap Location: /tmp
Comment 1 Halla Rempt 2019-02-08 09:55:50 UTC
Thanks for your report. I've asked the author to take a look (see https://phabricator.kde.org/D15584)
Comment 2 reptillia39 2019-02-08 16:27:48 UTC
I have tested the blending mode on Windows 10 x64, and assigned blending mode to brush. No crash. Converted space, no crash. 16f mode, no crash. 8i mode, no crash. I'm not really getting the issue here. I don't see this bug showing up on my Kubuntu VM either. Can't replicate.
Comment 3 reptillia39 2019-02-08 16:29:17 UTC
My guess is that it has to do with color management and operating system. Maybe with dependencies.  Logarithmic modes use log2() which doesn't show up in all the other blending modes, so it may have to do with something with that, though I doubt it.
Comment 4 Rebecca Breu 2019-02-08 18:56:43 UTC
I get the crash with both the latest nightly app image and with my build with the Docker image. Here the trace back and debug info from the docker build:

-----

#0  0x00007fffd4804f64 in cfColorBurnLogarithmic<unsigned char> (dst=98 'b', src=255 '\377')
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpFunctions.h:911
#1  cfColorDodgeLogarithmic<unsigned char> (dst=157 '\235', src=0 '\000')
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpFunctions.h:919
#2  KoCompositeOpGenericSC<KoBgrU8Traits, &(unsigned char cfColorDodgeLogarithmic<unsigned char>(unsigned char, unsigned char))>::composeColorChannels<false, true> (src=0xa487844 "", srcAlpha=<optimized out>,
    dst=0x7fffa861b3e4 "\235~u\377k=0\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377g8*\377"..., dstAlpha=255 '\377',
    maskAlpha=<optimized out>, opacity=<optimized out>, channelFlags=...)
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpGeneric.h:74
#3  0x00007fffd4823350 in KoCompositeOpBase<KoBgrU8Traits, KoCompositeOpGenericSC<KoBgrU8Traits, cfColorDodgeLogarithmic<unsigned char> > >::genericComposite<false, false, true> (channelFlags=..., params=..., this=<optimized out>)
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpBase.h:115
#4  KoCompositeOpBase<KoBgrU8Traits, KoCompositeOpGenericSC<KoBgrU8Traits, &(unsigned char cfColorDodgeLogarithmic<unsigned char>(unsigned char, unsigned char))> >::composite (this=<optimized out>, params=...)
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpBase.h:81
#5  0x00007ffff0b1d4d6 in KoColorSpace::bitBlt (this=0x29f4500, srcSpace=0x29f4500, params=..., op=op@entry=0x2902f90,
    renderingIntent=renderingIntent@entry=KoColorConversionTransformation::IntentPerceptual, conversionFlags=...)
    at /home/appimage/persistent/krita/libs/pigment/KoColorSpace.cpp:511
#6  0x00007ffff5725da3 in KisPainter::bitBltImpl<false> (this=0x7fffafffed30, dstX=384, dstY=512, srcDev=..., srcX=384, srcY=512,
    srcWidth=srcWidth@entry=128, srcHeight=srcHeight@entry=448) at /home/appimage/persistent/krita/libs/image/kis_painter.cc:751
#7  0x00007ffff571d7b0 in KisPainter::bitBlt (this=<optimized out>, dstX=<optimized out>, dstY=<optimized out>, srcDev=...,
    srcX=<optimized out>, srcY=<optimized out>, srcWidth=128, srcHeight=448)
    at /home/appimage/persistent/krita/libs/image/kis_painter.cc:773
#8  0x00007ffff571d83a in KisPainter::bitBlt (this=this@entry=0x7fffafffed30, pos=..., srcDev=..., srcRect=...)
    at /home/appimage/persistent/krita/libs/image/kis_painter.cc:779
#9  0x00007ffff5827c74 in KisLayerProjectionPlane::apply (this=0xb7201a0, painter=0x7fffafffed30, rect=...)
    at /home/appimage/persistent/krita/libs/image/kis_layer_projection_plane.cpp:99
#10 0x00007ffff57debcb in KisAsyncMerger::compositeWithProjection (rect=..., leaf=..., this=<optimized out>, this=<optimized out>)
    at /home/appimage/persistent/krita/libs/image/kis_async_merger.cpp:355
--Type <RET> for more, q to quit, c to continue without paging--
#11 KisAsyncMerger::startMerge (this=this@entry=0xcc90638, walker=..., notifyClones=notifyClones@entry=true)
    at /home/appimage/persistent/krita/libs/image/kis_async_merger.cpp:279
#12 0x00007ffff592baf9 in KisUpdateJobItem::runMergeJob (this=0xcc905f0)
    at /home/appimage/appimage-workspace/krita-build/libs/image/../../../../persistent/krita/libs/image/kis_update_job_item.h:118
#13 KisUpdateJobItem::run (this=0xcc905f0)
    at /home/appimage/appimage-workspace/krita-build/libs/image/../../../../persistent/krita/libs/image/kis_update_job_item.h:86
#14 0x00007ffff3cd14b2 in ?? () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5
#15 0x00007ffff3cd431f in ?? () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5
#16 0x00007fffedbad184 in start_thread (arg=0x7fffaffff700) at pthread_create.c:312
#17 0x00007ffff342903d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

-----

Krita

  Version: 4.2.0-pre-alpha (git ab53dc1)

Qt

  Version (compiled): 5.10.0
  Version (loaded): 5.10.0

OS Information

  Build ABI: x86_64-little_endian-lp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: linux
  Kernel Version: 4.9.0-8-amd64
  Pretty Productname: Ubuntu 14.04.5 LTS
  Product Type: ubuntu
  Product Version: 14.04

OpenGL Info

  Vendor:  VMware, Inc.
  Renderer:  "Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits)"
  Version:  "2.1 Mesa 10.1.3"
  Shading language:  1.30
  Requested format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 0, colorSpace QSurfaceFormat::ColorSpace(DefaultColorSpace), profile  QSurfaceFormat::OpenGLContextProfile(CompatibilityProfile))
  Current format:    QSurfaceFormat(version 2.1, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 0, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 0, colorSpace QSurfaceFormat::ColorSpace(DefaultColorSpace), profile  QSurfaceFormat::OpenGLContextProfile(NoProfile))
     Version: 2.1
     Supports deprecated functions true
     is OpenGL ES: false

Hardware Information

  GPU Acceleration: auto
  Memory: 15796 Mb
  Number of Cores: 4
  Swap Location: /tmp
Comment 5 Rebecca Breu 2019-02-08 19:03:44 UTC
And that was missing the actual error:

received signal SIGFPE, Arithmetic exception.
Comment 6 reptillia39 2019-02-08 19:09:25 UTC
Does this happen with just Color Dodge Logarithmic? I'd like to know if there are other problematic blend modes.
Comment 7 Rebecca Breu 2019-02-08 20:13:51 UTC
Only with Burn Logarithmic. (I hope I didn't miss any, though I definitely tried to go trough all.)


Thread 830 "Thread (pooled)" received signal SIGFPE, Arithmetic exception.
[Switching to Thread 0x7fffae7fc700 (LWP 8503)]
0x00007fffd4226de5 in cfColorBurnLogarithmic<unsigned char> (src=0 '\000', dst=255 '\377')
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpFunctions.h:908
908	    return scale<T>(log2(1.0 + abs(fsrc)/abs(inv(.999999))/8));
(gdb)
(gdb) backtrace
#0  0x00007fffd4226de5 in cfColorBurnLogarithmic<unsigned char> (src=0 '\000', dst=255 '\377')
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpFunctions.h:908
#1  0x00007fffd481c679 in KoCompositeOpGenericSC<KoBgrU8Traits, cfColorBurnLogarithmic<unsigned char> >::composeColorChannels<false, true>
    (channelFlags=..., opacity=<optimized out>, maskAlpha=255 '\377', dstAlpha=255 '\377',
    dst=0x7fffa4160220 '\377' <repeats 200 times>..., srcAlpha=<optimized out>, src=0xa487390 "")
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpGeneric.h:74
#2  KoCompositeOpBase<KoBgrU8Traits, KoCompositeOpGenericSC<KoBgrU8Traits, cfColorBurnLogarithmic<unsigned char> > >::genericComposite<false, false, true> (channelFlags=..., params=..., this=<optimized out>)
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpBase.h:115
#3  KoCompositeOpBase<KoBgrU8Traits, KoCompositeOpGenericSC<KoBgrU8Traits, &(unsigned char cfColorBurnLogarithmic<unsigned char>(unsigned char, unsigned char))> >::composite (this=<optimized out>, params=...)
    at /home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpBase.h:81
#4  0x00007ffff0b1d4d6 in KoColorSpace::bitBlt (this=0x29f5590, srcSpace=0x29f5590, params=..., op=op@entry=0x28ecfa0,
    renderingIntent=renderingIntent@entry=KoColorConversionTransformation::IntentPerceptual, conversionFlags=...)
    at /home/appimage/persistent/krita/libs/pigment/KoColorSpace.cpp:511
#5  0x00007ffff5725da3 in KisPainter::bitBltImpl<false> (this=0x7fffae7fbd30, dstX=512, dstY=192, srcDev=..., srcX=512, srcY=192,
    srcWidth=srcWidth@entry=512, srcHeight=srcHeight@entry=320) at /home/appimage/persistent/krita/libs/image/kis_painter.cc:751
#6  0x00007ffff571d7b0 in KisPainter::bitBlt (this=<optimized out>, dstX=<optimized out>, dstY=<optimized out>, srcDev=...,
    srcX=<optimized out>, srcY=<optimized out>, srcWidth=512, srcHeight=320)
    at /home/appimage/persistent/krita/libs/image/kis_painter.cc:773
#7  0x00007ffff571d83a in KisPainter::bitBlt (this=this@entry=0x7fffae7fbd30, pos=..., srcDev=..., srcRect=...)
    at /home/appimage/persistent/krita/libs/image/kis_painter.cc:779
#8  0x00007ffff5827c74 in KisLayerProjectionPlane::apply (this=0xb67bcb0, painter=0x7fffae7fbd30, rect=...)
    at /home/appimage/persistent/krita/libs/image/kis_layer_projection_plane.cpp:99
#9  0x00007ffff57debcb in KisAsyncMerger::compositeWithProjection (rect=..., leaf=..., this=<optimized out>, this=<optimized out>)
    at /home/appimage/persistent/krita/libs/image/kis_async_merger.cpp:355
#10 KisAsyncMerger::startMerge (this=this@entry=0x4a28b88, walker=..., notifyClones=notifyClones@entry=true)
    at /home/appimage/persistent/krita/libs/image/kis_async_merger.cpp:279
#11 0x00007ffff592baf9 in KisUpdateJobItem::runMergeJob (this=0x4a28b40)
    at /home/appimage/appimage-workspace/krita-build/libs/image/../../../../persistent/krita/libs/image/kis_update_job_item.h:118
#12 KisUpdateJobItem::run (this=0x4a28b40)
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/appimage/appimage-workspace/krita-build/libs/image/../../../../persistent/krita/libs/image/kis_update_job_item.h:86
#13 0x00007ffff3cd14b2 in ?? () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5
#14 0x00007ffff3cd431f in ?? () from /home/appimage/appimage-workspace/deps/usr/lib/libQt5Core.so.5
#15 0x00007fffedbad184 in start_thread (arg=0x7fffae7fc700) at pthread_create.c:312
#16 0x00007ffff342903d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
Comment 8 reptillia39 2019-02-08 20:18:52 UTC
Okay, I'll get around using a different code, but similar formula for the logarithmic mode this or next week.
Comment 9 M 2019-02-09 08:44:24 UTC
Yes, it happens with Burn - Logarithmic as well as Color Dodge - Logarithmic. Thank you, didn't notice that one at first.
Comment 10 reptillia39 2019-02-17 01:50:16 UTC
Created attachment 118143 [details]
What the Burn Blend Mode should look like

As I am having a computer overheating problem, I have to request somebody to verify that this code replacement to current burn log function works. The sample shows the end result when this works.

template<class T>
inline T cfColorBurnLogarithmic(T src, T dst) {
    using namespace Arithmetic;
    //Also known as Darken from EffectBank/Illusions.hu. IFS Illusions had used this blending mode.
    
    qreal fsrc = scale<qreal>(abs(src));
    qreal fdst = scale<qreal>(abs(dst));
    
    if (dst == unitValue<T>()) {return scale<T>(log2(1.0 + fsrc/0.000000125);}  
    
    return scale<T>(log2(1.0 + fsrc/((inv(fdst))/8))); 
}
Comment 11 reptillia39 2019-02-17 01:55:55 UTC
Source of test images - https://www.getpaint.net/doc/latest/BlendModes.html
Comment 12 Rebecca Breu 2019-02-17 10:41:02 UTC
Missing closing paranthesis in the second to last line. After fixing that, I get:


In file included from /home/appimage/persistent/krita/libs/pigment/KoColorSpaceAbstract.h:29:0,
                 from /home/appimage/persistent/krita/libs/pigment/colorspaces/KoSimpleColorSpace.h:26,
                 from /home/appimage/persistent/krita/libs/pigment/colorspaces/KoRgbU8ColorSpace.h:24,
                 from /home/appimage/persistent/krita/libs/pigment/colorspaces/KoRgbU8ColorSpace.cpp:19:
/home/appimage/persistent/krita/libs/pigment/KoColorSpaceMaths.h: In instantiation of ‘class KoColorSpaceMaths<int, double>’:
/home/appimage/persistent/krita/libs/pigment/KoColorSpaceMaths.h:589:74:   required from ‘TRet Arithmetic::scale(T) [with TRet = double; T = int]’
/home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpFunctions.h:905:39:   required from ‘T cfColorBurnLogarithmic(T, T) [with T = unsigned char]’
/home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOps.h:173:13:   required from ‘static void _Private::AddGeneralOps<Traits, true>::add(KoColorSpace*) [with Traits = KoBgrU8Traits]’
/home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOps.h:305:61:   required from ‘void addStandardCompositeOps(KoColorSpace*) [with _Traits_ = KoBgrU8Traits]’
/home/appimage/persistent/krita/libs/pigment/colorspaces/KoRgbU8ColorSpace.cpp:51:48:   required from here
/home/appimage/persistent/krita/libs/pigment/KoColorSpaceMaths.h:231:44: error: no type named ‘compositetype’ in ‘class KoColorSpaceMathsTraits<int>’
     typedef typename traits::compositetype src_compositetype;
                                            ^
In file included from /home/appimage/persistent/krita/libs/pigment/KoColorSpaceAbstract.h:29:0,
                 from /home/appimage/persistent/krita/libs/pigment/colorspaces/KoSimpleColorSpace.h:26,
                 from /home/appimage/persistent/krita/libs/pigment/colorspaces/KoLabColorSpace.h:24,
                 from /home/appimage/persistent/krita/libs/pigment/colorspaces/KoLabColorSpace.cpp:19:
/home/appimage/persistent/krita/libs/pigment/KoColorSpaceMaths.h: In instantiation of ‘class KoColorSpaceMaths<int, double>’:
/home/appimage/persistent/krita/libs/pigment/KoColorSpaceMaths.h:589:74:   required from ‘TRet Arithmetic::scale(T) [with TRet = double; T = int]’
/home/appimage/persistent/krita/libs/pigment/compositeops/KoCompositeOpFunctions.h:905:39:   required from ‘T cfColorBurnLogarithmic(T, T) [with T = short unsigned int]’
/home/appimage/persistent/krita/libs/pigment/colorspaces/../compositeops/KoCompositeOps.h:173:13:   required from ‘static void _Private::AddGeneralOps<Traits, true>::add(KoColorSpace*) [with Traits = KoLabU16Traits]’
/home/appimage/persistent/krita/libs/pigment/colorspaces/../compositeops/KoCompositeOps.h:305:61:   required from ‘void addStandardCompositeOps(KoColorSpace*) [with _Traits_ = KoLabU16Traits]’
/home/appimage/persistent/krita/libs/pigment/colorspaces/KoLabColorSpace.cpp:49:49:   required from here
/home/appimage/persistent/krita/libs/pigment/KoColorSpaceMaths.h:231:44: error: no type named ‘compositetype’ in ‘class KoColorSpaceMathsTraits<int>’
     typedef typename traits::compositetype src_compositetype;
                                            ^
make[2]: *** [libs/pigment/CMakeFiles/kritapigment.dir/colorspaces/KoLabColorSpace.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [libs/pigment/CMakeFiles/kritapigment.dir/colorspaces/KoRgbU8ColorSpace.cpp.o] Error 1
make[1]: *** [libs/pigment/CMakeFiles/kritapigment.dir/all] Error 2
make: *** [all] Error 2
Comment 13 reptillia39 2019-02-21 06:11:17 UTC
I got my computer overheating issue fixed, so I can test changes.

For Rebecca Breu, as you know how to compile and edit code by copy and pasting as well as having a computer where this bug can be reproduced (I can't reproduce it). Can you confirm this change works?

template<class T>
inline T cfColorBurnLogarithmic(T src, T dst) {
    using namespace Arithmetic;
    //Also known as Darken from EffectBank/Illusions.hu. IFS Illusions had used this blending mode.
    
    qreal fsrc = scale<qreal>(src);
    qreal fdst = scale<qreal>(dst);
    
    if (fdst == unitValue<T>()) {
    return scale<T>(log2(abs(1.0 + fsrc/inv(.999999)/8)));
    }  
    
    return scale<T>(log2(abs(1.0 + fsrc/inv(fdst)/8))); 
}

If it does work, I'll submit a patch on phabricator.

The changes I have made is to remove abs inside, and then wrap the absolute next to log2 to force everything to go to positive. And yes, it does compile.
Comment 14 reptillia39 2019-02-21 16:28:18 UTC
https://phabricator.kde.org/D19204

Patch submitted for testing.
Comment 15 reptillia39 2019-02-23 14:39:06 UTC
Removed those modes and I have mentioned why.