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 (SIGFPE), or triggering an infinite loop warning
(WARNING: Grid Scale Coeff is too high! That is surely a bug!
) in
KisGridDecoration::drawDecoration (since effectiveSize == 0).
So make sure the minimum spacing after transform is 1px.
Note: Undo/redo of scale image while the grid is visible causes a safe assert / warning. It seems that the grid scaling step checks the grid config, and this shouldn't happen from the undo thread.
SAFE ASSERT (krita): "(static_cast<QApplication *>(QCoreApplication::instance())) && (static_cast<QApplication *>(QCoreApplication::instance()))->thread() == QThread::currentThread()" in file /libs/ui/kis_config.cc, line 56
WARNING: KisConfig: requested config synchronization from nonGUI thread! Called from: [
0: 0 libkritaglobal.20.0.0.dylib 0x0000000106ed84b4 _Z12kisBacktracev + 76
1: 1 libkritaui.20.0.0.dylib 0x0000000105b94528 _ZN9KisConfigD2Ev + 260
2: 2 libkritaui.20.0.0.dylib 0x0000000105f0aa18 _ZN11KisDocument13setGridConfigERK13KisGridConfig + 228
3: 3 libkritaui.20.0.0.dylib 0x0000000105fb7b2c _ZZN26KisDecorationsWrapperLayer9transformERK10QTransformEN11UndoCommand11doTransformES2_ + 240
4: 4 libkritaui.20.0.0.dylib 0x0000000105fb7a24 _ZZN26KisDecorationsWrapperLayer9transformERK10QTransformEN11UndoCommand4undoEv + 48
5: 5 libkritacommand.20.0.0.dylib 0x00000001052261d0 _ZN13KUndo2Command18undoMergedCommandsEv + 32
6: 6 libkritacommand.20.0.0.dylib 0x00000001052285e4 _ZN12KUndo2QStack4undoEv + 76
7: 7 libkritacommand.20.0.0.dylib 0x000000010522c2a0 _ZN21KisSurrogateUndoStore7undoAllEv + 44
8: 8 libkritaimage.20.0.0.dylib 0x0000000107220dd4 _ZN33KisStrokeStrategyUndoCommandBased16doStrokeCallbackEP16KisStrokeJobData + 196
9: 9 libkritaimage.20.0.0.dylib 0x000000010701feec _ZN16KisUpdateJobItem3runEv + 336
10: 10 QtCore 0x0000000109326ea4 _ZN10QSemaphore10tryAcquireEii + 676
11: 11 QtCore 0x0000000109322b08 _ZN7QThread11qt_metacallEN11QMetaObject4CallEiPPv + 1296
12: 12 libsystem_pthread.dylib 0x0000000196952f94 _pthread_start + 136
13: 13 libsystem_pthread.dylib 0x000000019694dd34 thread_start + 8
]
There's also an issue that undoing the scale down of 1px will cause the grid to be larger than before, as it will undo the intended scaling (.20) instead of the actual corrected scaling (1.0). But since the undo affects the current grid spacing, attempting to adjust the scale to the actual scale would also have inconsistent effects if spacing were to be changed before redo.
Test Plan
- Turn on View->Show Grid. In the Grids and Guides Docker, set rectangular grid spacing to 1px.
- Image->Scale Image To New Size, scale the image to less than 50% size. The grid should remain visible with 1px spacing, rather than crashing Krita with SIGFPE or (if the compiler ignores that) the grid disappearing with warnings.
Formalities Checklist
-
I confirmed this builds. -
I confirmed Krita ran and the relevant functions work. -
I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!) -
I made sure my commits build individually and have good descriptions as per KDE guidelines. -
I made sure my code conforms to the standards set in the HACKING file. -
I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy. -
Does the patch add a user-visible feature? If yes, is there a documentation MR ready for it at Krita Documentation Repository?
Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.