Fix the creation of backend nodes if using the parent entity constructor


On an already running simulation, when adding entities with the
constructor taking a parent node, no backend node was created if a
component was previously added to the tree with QEntity::addComponent().

In QEntity::addComponent(), we call _q_ensureBackendNodeCreated() on the
component, creating the backend nodes of the whole tree, which marks
them with m_hasBackendNode = true. Then, when we try to create a new
entity by using the constructor which takes a parent entity (e.g. `auto
positions = new QAttribute(entity);`), we effectively call
NodePostConstructorInit::addNode(). But since the parent node is still
in the m_nodesToConstruct queue (we didn't return to the event loop
yet), the function did not queue the new entity for backend node
creation.

To fix this, allow the new entity to be added in the creation queue,
even if the parent in the queue has already been created itself
(m_hasBackendNode == true).

* The bug does not happen when creating the whole tree in advance and
then calling setRootEntity().
* It also does not happen if not calling QEntity::addComponent(),
because then the parent backend node is not created, so it will create
its child one automatically once itself is created.
* Finally, not giving a parent node and explicitly calling setParent()
later was also working.

QTBUG-120964 contains an example materializing the crash, caused by the
missing Attribute backend node.

Fixes: QTBUG-77139
Fixes: QTBUG-100387
Fixes: QTBUG-120964
Pick-to: 6.6 6.7
Change-Id: I908f1b5ecc2a845564d38bc634a2c645ad1a8074
Reviewed-by: Mike Krus <mike.krus@kdab.com>
commit0d4a4a9eff4fad9e81e5ca5fee441ce3bd367835
parent83ae9c13ea66b8a80695c8cee0b459a4cf37d0db
authorAurélien Brooke <aurelien@bahiasoft.fr>
committerAurélien Brooke <aurelien@bahiasoft.fr>
commit timeMon, 15 Jan 2024 17:25:20 +0100