The following code is working without problem with Qt 5.9.x and with Qt 5.10 ( MinGW 32bit) it returns
null pointer for Qt3DRender::QGeometryFactory *geometry_factory ( Qt3DRender::QGeometry *geometry )
Qt3DRender::QMesh * mesh = new Qt3DRender::QMesh(); QUrl url("pathto/mesh.obj"); mesh->setSource( url ); if (mesh->source().isEmpty()) { throw std::runtime_error("A source is needed to build the geometry."); } Qt3DRender::QGeometryFactory *geometry_factory = mesh->geometryFactory().data(); // << mesh->geometryFactory().data() returns null pointer if (!geometry_factory) { throw std::runtime_error("Could not construct geometry from mesh: " + mesh->source().toString().toStdString()); } Qt3DRender::QGeometry *geometry = geometry_factory->operator()();
Same issue has been reported with Qt 5.8 ( https://bugreports.qt.io/browse/QTBUG-59066 )
and looks like it is still unresolved in Qt 5.10 ( but in Qt 5.9 works... )
I compared the source code between 5.9 and 5.10 and i noticed the following differences:
In Qt 5.9.3 right after we set the source setGeometryFactory is called
void QMesh::setSource(const QUrl& source) { Q_D(QMesh); if (d->m_source == source) return; d->m_source = source; // update the functor QGeometryRenderer::setGeometryFactory(QGeometryFactoryPtr(new MeshFunctor(d->m_source, d->m_meshName))); const bool blocked = blockNotifications(true); emit sourceChanged(source); blockNotifications(blocked); }
While in Qt 5.10 it calls updateFunctor from QMeshPrivate which checks if m_scene is set before
void QMesh::setSource(const QUrl& source) { Q_D(QMesh); if (d->m_source == source) return; d->m_source = source; d->updateFunctor(); const bool blocked = blockNotifications(true); emit sourceChanged(source); blockNotifications(blocked); }
void QMeshPrivate::updateFunctor() { Q_Q(QMesh); Qt3DCore::QAspectEngine *engine = m_scene ? m_scene->engine() : nullptr; if (engine) q->setGeometryFactory(QGeometryFactoryPtr(new MeshLoaderFunctor(q, engine))); }
There is not public interface to set m_scene and that is the reason why i always receive null QGeometryFactory pointer
- duplicates
-
QTBUG-59066 QMesh does not set its QGeometryRenderer::geometry property
-
- Open
-
For Gerrit Dashboard: QTBUG-65506 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
217321,2 | QMesh: do not rely on QAspectEngine to create QGeometryFactory | 5.10 | qt/qt3d | Status: MERGED | +2 | 0 |
217329,2 | QMesh: do not rely on QAspectEngine to create QGeometryFactory | dev | qt/qt3d | Status: MERGED | +2 | 0 |