Repository navigation
Write the node size only when it changed - #580
Open
paceholder wants to merge 1 commit into
Open
paceholder wants to merge 1 commit into
paceholder wants to merge 1 commit into
Conversation
The default geometries wrote the size on every recompute. A model that emitted nodeUpdated from setNodeData(Size), as the guide advised, then recursed without end. AbstractNodeGeometry::storeSize() now writes a size only when it differs from the stored one, so a loop ends after one pass. Both default geometries use it, and a custom geometry can call it. The guide said that such an emit starts an endless recursion. It now says only that the emit is not needed, and tells a custom geometry to store the size with storeSize(). See #568
paceholder
force-pushed
the
fix-size-write-loop
branch
from
December 2, 2026 20:45
e9cbb28 to
b444058
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Description
The default geometries wrote
NodeRole::Sizeinto the model on every recompute, also when the value did not change. A model that emittednodeUpdatedfromsetNodeData(Size), as the advanced guide advised until #576, then recursed without end: the scene writesSizewhile it handlesnodeUpdated, the write emitsnodeUpdated, and so on.The new protected function
AbstractNodeGeometry::storeSize(nodeId, size)compares the new size with the stored one and writes only if they differ. Both default geometries end with this one call. A recompute that changes nothing writes nothing, and a loop ends after one pass. A custom geometry can call the same function, so it does not have to repeat the check. There is no new state, no flag and no layout change: the function is protected and not virtual. The library and all the example models store the size and emit nothing, so for them the only visible change is fewer writes (a new node used to write the size more than once).A model that emits
nodeUpdatedon everySizewrite still gets one nestednodeUpdated: the write that changes the size emits, the scene recomputes once more inside the first handler, finds the same size and stops. I measured the nested depth in the loop test: 1. The guide says that this emit is not needed. A guard that removes the nested pass would need a flag per node, and I did not add it.The guide said that emitting
nodeUpdatedon aSizewrite "starts an endless recursion". It now says only that the emit is not needed. The change-notifications guide tells a custom geometry to store the size withstoreSize(). The guide does not promise anything about a model that emits anyway.The size itself stays a value that the geometry computes and the model stores. Who should own the size is a question for v4 (#568, #577).
Testing
Sizerole also build.test/src/TestSizeWrite.cpp, both failed on the old code:Not tested: Qt 5, Linux, Windows, and a node with a real embedded widget (the tests use the test graph model without a widget). A custom geometry that writes the size on every recompute without
storeSize()keeps its old behavior.Breaking changes?
No. One protected, non-virtual function is added to
AbstractNodeGeometry. The size and the layout of the class do not change.Related issue
See #568.