実行時に作成および削除する必要があるエンティティがあります。エンティティには、マテリアルとメッシュ コンポーネントしかありません。マテリアルは QTextureImage を使用した QDiffuseMapMaterial です。
エンティティがシーンから追加および削除を開始すると、次のアサートでアプリケーションがクラッシュすることがあります。
qt_assert: ASSERT: ファイル内の "img != nullptr" ../../include/Qt3DRender/5.8.0/Qt3DRender/private/../../../../../src/render/texture /apitexturemanager_p.h、286行目
しかし、残念ながら、なぜそれが起こるのかわかりません。私はこの方法でエンティティを追加しています:
QEntity * visibleObject = new QEntity();
QDiffuseMapMaterial * material = new QDiffuseMapMaterial();
QTextureImage * diffuseTextureImage = new QTextureImage();
diffuseTextureImage->setSource(QUrl("qrc:/resources/tile.png"));
material->diffuse()->addTextureImage(diffuseTextureImage);
visibleObject->addComponent(material);
// set mesh
QPlaneMesh * mesh = new QPlaneMesh();
mesh->setWidth(1.0 / 2);
mesh->setHeight(1.0 / 2);
visibleObject->addComponent(mesh);
visibleObject->setParent(_rootEntity);
そして、次のように削除します。
delete visibleObject;
_rootEntity
cpp コードで定義されたシーン ルート エンティティです。Scene3D を使用して QML ファイルで定義されたシーン:
Scene3D {
id: scene
anchors.fill: parent
aspects: ["render", "logic", "input"]
entity: rootEntity
}
そして_rootEntity
、このように渡しました:
context->setContextProperty("rootEntity", _rootEntity);
必要に応じて、問題を再現する簡単な例を用意できます。
ありがとう。