Bug 490898

Summary: Krita crashing (SIGFPE) when scaling the image to new size while having the grid enabled at 1px spacing
Product: [Applications] krita Reporter: denkibugreport
Component: Resize/Scale Image/LayerAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version: 5.2.3   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Backtrace

Description denkibugreport 2024-07-27 16:57:01 UTC
Created attachment 172054 [details]
Backtrace

SUMMARY
When trying to downscale an image while having the grid enabled at 1px spacing, Krita crashes

STEPS TO REPRODUCE
1. Create a new Image (Size doesn't matter)
2. Set the X and Y spacing of the grid to 1px
3. Show the grid
4. Scale the image down to a lower size

OBSERVED RESULT
Krita crashes

EXPECTED RESULT
Image scales down to the new size

SOFTWARE/OS VERSIONS
Linux: 6.10.1-arch1-1
KDE Plasma Version: 6.1.3
KDE Frameworks Version: 6.4.0
Qt Version: 6.7.2

BACKTRACE:
Downloading source file /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc

[###                                                                                                                                                                    ]
                                                                                                                                                                           
Breakpoint 2 at 0x7ffff54ae260: file /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc, line 80.
Breakpoint 3 at 0x7ffff54ae2c0: file /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc, line 103.
Continuing.
[New Thread 0x7fffef8006c0 (LWP 31432)]
Downloading separate debug info for /usr/lib/libGLX_nvidia.so.0

[###                                                                                                                                                                    ]
                                                                                                                                                                           
Downloading separate debug info for /usr/lib/libnvidia-glsi.so.555.58.02

[###                                                                                                                                                                    ]
                                                                                                                                                                           
Downloading separate debug info for /usr/lib/libnvidia-tls.so.555.58.02

[###                                                                                                                                                                    ]
                                                                                                                                                                           
Downloading separate debug info for /usr/lib/libnvidia-glcore.so.555.58.02

[###                                                                                                                                                                    ]
                                                                                                                                                                           
Downloading separate debug info for /usr/lib/libnvidia-gpucomp.so.555.58.02

[###                                                                                                                                                                    ]
                                                                                                                                                                           
[Thread 0x7fffef8006c0 (LWP 31432) exited]
[New Thread 0x7fffef8006c0 (LWP 31437)]
[Thread 0x7fffef8006c0 (LWP 31437) exited]
[New Thread 0x7fffef8006c0 (LWP 31438)]
[Thread 0x7fffef8006c0 (LWP 31438) exited]
[New Thread 0x7fffef8006c0 (LWP 31439)]
[New Thread 0x7fffe58006c0 (LWP 31440)]
[New Thread 0x7fffe4e006c0 (LWP 31442)]
[New Thread 0x7fffdda006c0 (LWP 31443)]
[New Thread 0x7fffdd0006c0 (LWP 31444)]
[New Thread 0x7fffd7e006c0 (LWP 31445)]
[New Thread 0x7fffd74006c0 (LWP 31446)]
[New Thread 0x7fffd6a006c0 (LWP 31447)]
[New Thread 0x7fffd60006c0 (LWP 31448)]
[New Thread 0x7fffd56006c0 (LWP 31449)]
[New Thread 0x7fffd4c006c0 (LWP 31450)]
[New Thread 0x7fffcbe006c0 (LWP 31451)]
[New Thread 0x7fffcb4006c0 (LWP 31452)]
[New Thread 0x7fffcaa006c0 (LWP 31453)]
[New Thread 0x7fffca0006c0 (LWP 31454)]
[New Thread 0x7fffc96006c0 (LWP 31455)]
[New Thread 0x7fffc8c006c0 (LWP 31456)]
[New Thread 0x7fffbfe006c0 (LWP 31457)]
[Thread 0x7fffbfe006c0 (LWP 31457) exited]
[Thread 0x7fffc8c006c0 (LWP 31456) exited]
[Thread 0x7fffc96006c0 (LWP 31455) exited]
[Thread 0x7fffca0006c0 (LWP 31454) exited]
[Thread 0x7fffcaa006c0 (LWP 31453) exited]
[Thread 0x7fffcb4006c0 (LWP 31452) exited]
[Thread 0x7fffcbe006c0 (LWP 31451) exited]
[Thread 0x7fffd4c006c0 (LWP 31450) exited]
[Thread 0x7fffd56006c0 (LWP 31449) exited]
[Thread 0x7fffd60006c0 (LWP 31448) exited]
[Thread 0x7fffd6a006c0 (LWP 31447) exited]
[Thread 0x7fffd74006c0 (LWP 31446) exited]
[Thread 0x7fffd7e006c0 (LWP 31445) exited]
[Thread 0x7fffdd0006c0 (LWP 31444) exited]
[Thread 0x7fffdda006c0 (LWP 31443) exited]
[Thread 0x7fffe4e006c0 (LWP 31442) exited]
[New Thread 0x7fffdda006c0 (LWP 31551)]
[New Thread 0x7fffc96006c0 (LWP 31560)]
[New Thread 0x7fffd4c006c0 (LWP 31561)]
[Thread 0x7fffc96006c0 (LWP 31560) exited]
[New Thread 0x7fffc96006c0 (LWP 31562)]
[New Thread 0x7fffc8c006c0 (LWP 31563)]
[New Thread 0x7fffdd0006c0 (LWP 31564)]
[New Thread 0x7fffd7e006c0 (LWP 31565)]
[New Thread 0x7fffd74006c0 (LWP 31566)]
[New Thread 0x7fffd6a006c0 (LWP 31567)]
[New Thread 0x7fffd60006c0 (LWP 31568)]
[New Thread 0x7fffd56006c0 (LWP 31569)]
[New Thread 0x7fffcbe006c0 (LWP 31570)]
[New Thread 0x7fffcb4006c0 (LWP 31571)]
[New Thread 0x7fffcaa006c0 (LWP 31572)]
[New Thread 0x7fffca0006c0 (LWP 31573)]
[New Thread 0x7fffbfe006c0 (LWP 31574)]
[New Thread 0x7fffbf4006c0 (LWP 31575)]
[New Thread 0x7fffbea006c0 (LWP 31576)]

Thread 1 "krita" hit Breakpoint 2, __cxxabiv1::__cxa_throw (obj=0x555559261f30, tinfo=0x7fffdf0032a0 <typeinfo for OpenColorIO_v2_3::Exception>, dest=0x7fffded13b00 <OpenColorIO_v2_3::Exception::~Exception()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:80
warning: 80	/usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc: No such file or directory
Continuing.
[Thread 0x7fffcaa006c0 (LWP 31572) exited]
[Thread 0x7fffbea006c0 (LWP 31576) exited]
[Thread 0x7fffd56006c0 (LWP 31569) exited]
[Thread 0x7fffd60006c0 (LWP 31568) exited]
[Thread 0x7fffcbe006c0 (LWP 31570) exited]
[Thread 0x7fffd74006c0 (LWP 31566) exited]
[Thread 0x7fffd6a006c0 (LWP 31567) exited]
[Thread 0x7fffd7e006c0 (LWP 31565) exited]
[Thread 0x7fffca0006c0 (LWP 31573) exited]
[Thread 0x7fffbf4006c0 (LWP 31575) exited]
[Thread 0x7fffbfe006c0 (LWP 31574) exited]
[Thread 0x7fffdd0006c0 (LWP 31564) exited]
[Thread 0x7fffc8c006c0 (LWP 31563) exited]
[Thread 0x7fffcb4006c0 (LWP 31571) exited]
[Thread 0x7fffc96006c0 (LWP 31562) exited]
[New Thread 0x7fffcb4006c0 (LWP 31751)]
[New Thread 0x7fffbfe006c0 (LWP 31752)]
[New Thread 0x7fffbf4006c0 (LWP 31753)]
[New Thread 0x7fffca0006c0 (LWP 31754)]
[New Thread 0x7fffdd0006c0 (LWP 31755)]
[New Thread 0x7fffd7e006c0 (LWP 31756)]
[New Thread 0x7fffd74006c0 (LWP 31757)]
[New Thread 0x7fffd6a006c0 (LWP 31758)]
[New Thread 0x7fffd60006c0 (LWP 31759)]
[New Thread 0x7fffd56006c0 (LWP 31760)]
[New Thread 0x7fffcbe006c0 (LWP 31761)]
[New Thread 0x7fffcaa006c0 (LWP 31762)]
[New Thread 0x7fffc96006c0 (LWP 31763)]
[New Thread 0x7fffc8c006c0 (LWP 31764)]
[New Thread 0x7fffbea006c0 (LWP 31767)]
[New Thread 0x7fffbcc006c0 (LWP 31770)]
[New Thread 0x7fffb1a006c0 (LWP 31771)]
[New Thread 0x7fffb10006c0 (LWP 31772)]
[New Thread 0x7fffb3e006c0 (LWP 31818)]

Thread 1 "krita" hit Breakpoint 2, __cxxabiv1::__cxa_throw (obj=0x555559ff01c0, tinfo=0x7fffdf0032a0 <typeinfo for OpenColorIO_v2_3::Exception>, dest=0x7fffded13b00 <OpenColorIO_v2_3::Exception::~Exception()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:80
80	in /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc
Continuing.

Thread 1 "krita" hit Breakpoint 2, __cxxabiv1::__cxa_throw (obj=0x55555a298fc0, tinfo=0x7fffdf0032a0 <typeinfo for OpenColorIO_v2_3::Exception>, dest=0x7fffded13b00 <OpenColorIO_v2_3::Exception::~Exception()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:80
80	in /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc
Continuing.
[Thread 0x7fffd60006c0 (LWP 31759) exited]
[Thread 0x7fffbcc006c0 (LWP 31770) exited]
[Thread 0x7fffc96006c0 (LWP 31763) exited]
[Thread 0x7fffd74006c0 (LWP 31757) exited]
[Thread 0x7fffd7e006c0 (LWP 31756) exited]
[Thread 0x7fffd6a006c0 (LWP 31758) exited]
[Thread 0x7fffdd0006c0 (LWP 31755) exited]
[Thread 0x7fffca0006c0 (LWP 31754) exited]
[Thread 0x7fffcaa006c0 (LWP 31762) exited]
[Thread 0x7fffbf4006c0 (LWP 31753) exited]
[Thread 0x7fffbfe006c0 (LWP 31752) exited]
[Thread 0x7fffcbe006c0 (LWP 31761) exited]
[Thread 0x7fffd56006c0 (LWP 31760) exited]
[Thread 0x7fffb10006c0 (LWP 31772) exited]
[Thread 0x7fffbea006c0 (LWP 31767) exited]
[Thread 0x7fffcb4006c0 (LWP 31751) exited]

Thread 1 "krita" hit Breakpoint 2, __cxxabiv1::__cxa_throw (obj=0x55555ab3d7d0, tinfo=0x7fffdf0032a0 <typeinfo for OpenColorIO_v2_3::Exception>, dest=0x7fffded13b00 <OpenColorIO_v2_3::Exception::~Exception()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:80
80	in /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc
Continuing.
[New Thread 0x7fffbea006c0 (LWP 31822)]
[New Thread 0x7fffcb4006c0 (LWP 31823)]
[New Thread 0x7fffb10006c0 (LWP 31852)]

Thread 62 "Thread (pooled)" received signal SIGFPE, Arithmetic exception.
[Switching to Thread 0x7fffb10006c0 (LWP 31852)]
0x00007ffff7753cf1 in KisAlgebra2D::wrapValue<int, (int*)0> (value=<optimized out>, wrapBounds=<optimized out>) at /usr/src/debug/krita/krita-5.2.3/libs/global/kis_algebra_2d.h:452
452	    value %= wrapBounds;
#0  0x00007ffff7753cf1 in KisAlgebra2D::wrapValue<int, (int*)0> (value=<optimized out>, wrapBounds=<optimized out>) at /usr/src/debug/krita/krita-5.2.3/libs/global/kis_algebra_2d.h:452
#1  KisAlgebra2D::wrapValue<QPoint, (QPoint*)0> (value=..., wrapBounds=...) at /usr/src/debug/krita/krita-5.2.3/libs/global/kis_algebra_2d.h:470
#2  KisGridConfig::transform (this=0x7fffb0fff860, transform=...) at /usr/src/debug/krita/krita-5.2.3/libs/ui/canvas/kis_grid_config.cpp:55
#3  KisGridConfig::transform (this=0x7fffb0fff860, transform=...) at /usr/src/debug/krita/krita-5.2.3/libs/ui/canvas/kis_grid_config.cpp:31
#4  0x00007ffff7b3b700 in UndoCommand::doTransform (this=0x7fff74001490, transform=...) at /usr/src/debug/krita/krita-5.2.3/libs/ui/KisDecorationsWrapperLayer.cpp:135
#5  0x00007ffff6cd1948 in KUndo2QStack::push (this=0x555559aa4650, cmd=<optimized out>) at /usr/src/debug/krita/krita-5.2.3/libs/command/kundo2stack.cpp:724
#6  0x00007ffff7027d23 in KisTransformProcessingVisitor::visit (this=0x555556ada0a0, layer=0x555556686c00, undoAdapter=0x55555a72f5a8) at /usr/src/debug/krita/krita-5.2.3/libs/image/processing/kis_transform_processing_visitor.cpp:114
#7  0x00007ffff70192db in KisProcessingCommand::redo (this=0x55555a72f570) at /usr/src/debug/krita/krita-5.2.3/libs/image/commands_new/kis_processing_command.cpp:23
#8  KisProcessingCommand::redo (this=0x55555a72f570) at /usr/src/debug/krita/krita-5.2.3/libs/image/commands_new/kis_processing_command.cpp:20
#9  0x00007ffff70dd1d9 in KisStrokeStrategyUndoCommandBased::doStrokeCallback (this=0x555559ae5f60, data=<optimized out>) at /usr/src/debug/krita/krita-5.2.3/libs/image/kis_stroke_strategy_undo_command_based.cpp:126
#10 0x00007ffff6fad9a3 in KisUpdateJobItem::runImpl (this=0x555559c004f0) at /usr/src/debug/krita/build/libs/image/kritaimage_autogen/EWIEGA46WW/../../../../../krita-5.2.3/libs/image/kis_update_job_item.h:100
#11 KisUpdateJobItem::run (this=0x555559c004f0) at /usr/src/debug/krita/build/libs/image/kritaimage_autogen/EWIEGA46WW/../../../../../krita-5.2.3/libs/image/kis_update_job_item.h:49
#12 0x00007ffff58f3945 in QThreadPoolThread::run (this=0x55555a020a60) at thread/qthreadpool.cpp:100
#13 0x00007ffff58f261b in operator() (__closure=<optimized out>) at thread/qthread_unix.cpp:350
#14 (anonymous namespace)::terminate_on_exception<QThreadPrivate::start(void*)::<lambda()> > (t=...) at thread/qthread_unix.cpp:287
#15 QThreadPrivate::start (arg=0x55555a020a60) at thread/qthread_unix.cpp:310
#16 0x00007ffff52a339d in start_thread (arg=<optimized out>) at pthread_create.c:447
#17 0x00007ffff532849c in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
[Inferior 1 (process 31263) killed]
Comment 1 Bug Janitor Service 2024-07-30 14:07:33 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/2208
Comment 2 Dmitry Kazakov 2024-07-31 06:34:03 UTC
Git commit 6324ca44615fa33957c9d96fdfb16b58d4fe6674 by Dmitry Kazakov, on behalf of Freya Lupen.
Committed on 31/07/2024 at 06:33.
Pushed by dkazakov into branch 'master'.

Fix scaling down image with 1px grid spacing

Scaling the image scales the grid along with it. If the scale
was less than 50%, 1px grid spacing would be rounded down to 0,
causing modulo by zero, or triggering an infinite loop warning in
KisGridDecoration::drawDecoration (since effectiveSize == 0).
So make sure the minimum spacing after transform is 1px.

M  +3    -0    libs/ui/canvas/kis_grid_config.cpp

https://invent.kde.org/graphics/krita/-/commit/6324ca44615fa33957c9d96fdfb16b58d4fe6674
Comment 3 Dmitry Kazakov 2024-07-31 06:34:23 UTC
Git commit 6d6d980897856731e54c0d64ab5170a9b27ba434 by Dmitry Kazakov.
Committed on 31/07/2024 at 06:34.
Pushed by dkazakov into branch 'krita/5.2'.

Fix scaling down image with 1px grid spacing

Scaling the image scales the grid along with it. If the scale
was less than 50%, 1px grid spacing would be rounded down to 0,
causing modulo by zero, or triggering an infinite loop warning in
KisGridDecoration::drawDecoration (since effectiveSize == 0).
So make sure the minimum spacing after transform is 1px.


(cherry picked from commit 6324ca44615fa33957c9d96fdfb16b58d4fe6674)

Co-authored-by: Freya Lupen <penguinflyer2222@gmail.com>

M  +3    -0    libs/ui/canvas/kis_grid_config.cpp

https://invent.kde.org/graphics/krita/-/commit/6d6d980897856731e54c0d64ab5170a9b27ba434