diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp index 6f3fced1b78..125a128594d 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp @@ -53,28 +53,41 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands() QQuickDesignerSupport::polishItems(quickWindow()); QVector imageContainerVector; + + // Base state needs to be rendered twice to properly render shared resources, + // if there is more than one View3D and at least one of them is dirty. + bool dirtyView3d = false; + const QList view3dInstances = allView3DInstances(); + for (const auto &instance : view3dInstances) { + if (QQuickDesignerSupport::isDirty(instance.rootQuickItem(), + QQuickDesignerSupport::ContentUpdateMask)) { + dirtyView3d = true; + break; + } + } + if (dirtyView3d) + renderPreviewImage(); imageContainerVector.append(ImageContainer(0, renderPreviewImage(), -1)); - QList stateInstances = rootNodeInstance().stateInstances(); + QList stateInstances = rootNodeInstance().stateInstances(); - const QList groupInstances = allGroupStateInstances(); + const QList groupInstances = allGroupStateInstances(); - for (ServerNodeInstance instance : groupInstances) { - stateInstances.append(instance.stateInstances()); - } + for (const ServerNodeInstance &instance : groupInstances) + stateInstances.append(instance.stateInstances()); - for (ServerNodeInstance instance : std::as_const(stateInstances)) { - instance.activateState(); - QImage previewImage = renderPreviewImage(); - if (!previewImage.isNull()) - imageContainerVector.append(ImageContainer(instance.instanceId(), - renderPreviewImage(), - instance.instanceId())); - instance.deactivateState(); - } + for (ServerNodeInstance instance : std::as_const(stateInstances)) { + instance.activateState(); + QImage previewImage = renderPreviewImage(); + if (!previewImage.isNull()) + imageContainerVector.append(ImageContainer(instance.instanceId(), + renderPreviewImage(), + instance.instanceId())); + instance.deactivateState(); + } nodeInstanceClient()->statePreviewImagesChanged( - StatePreviewImageChangedCommand(imageContainerVector)); + StatePreviewImageChangedCommand(imageContainerVector)); slowDownRenderTimer(); handleExtraRender();