Bug 495708

Summary: Node.scaleNode doesn't work when parent node is None
Product: [Applications] krita Reporter: Evan Lee <evan.lee.v0>
Component: ScriptingAssignee: Krita Bugs <krita-bugs-null>
Status: REPORTED ---    
Severity: normal CC: halla
Priority: NOR    
Version First Reported In: nightly build (please specify the git hash!)   
Target Milestone: ---   
Platform: Other   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Evan Lee 2024-11-02 04:19:22 UTC
Version: 5.3.0-prealpha (git e031c83)
OS: Windows 11

Node.scaleNode fails to work on freshly created nodes not yet added to the document node tree. It doesn't work if I scale the node then add it to the tree. It works as expected if I add the node to the tree then scale it.

```python
from krita import *

def loadImageToNode(image: QImage, node: Node) -> None:
    # The format is hardcoded. Maybe condition on it later.
    image.convertToFormat(QImage.Format_ARGB32)
    w = image.width()
    h = image.height()
    size = 4*w*h
    imageData = image.constBits().asstring(size)
    node.setPixelData(imageData, 0, 0, w, h)

doc = Krita.instance().activeDocument()

image = QImage('<path to image>')
node = doc.createNode('asdf', 'paintlayer')
loadImageToNode(image, node)

activeNode = doc.activeNode()
parentNode = activeNode.parentNode()
parentNode.addChildNode(node, activeNode)

r = node.bounds()
node.scaleNode(QPointF(0,0), int(r.width()*0.48), int(r.height()*0.48), 'Bicubic')
print(int(r.width()*0.48), int(r.height()*0.48))

doc.refreshProjection()
```
Comment 1 Evan Lee 2024-11-02 04:28:43 UTC
https://invent.kde.org/graphics/krita/-/blob/master/libs/libkis/Node.cpp#L700

This line is pretty common `if (!d->node->parent()) return;`. Is it really needed though? I would expect most transformations to be independent of the parent.
Comment 2 Halla Rempt 2024-11-02 09:18:49 UTC
If the node doesn't have a parent, then exactBounds() might fail, iirc.
Comment 3 Evan Lee 2024-11-02 12:48:08 UTC
(In reply to Halla Rempt from comment #2)
> If the node doesn't have a parent, then exactBounds() might fail, iirc.

I browsed the code. It looks like that's true for mask layers which is reasonable. For non-mask layers, it doesn't seem like parent is required.