Unhandled exception using Qt53DRenderd.dll in VC 2013 proj
-
Hi All,
I am a newbie in Qt. Currently using Qt5.6 and VC 2013 on Win7.
I came across a sample in qt3d that uses the assimp lib (assimp-cpp). I tried that on QtCreator and it ran without issues. However, when I tried to use the same code in my VC++ sample project, I encountered runtime exception on the execution of the following statement,engine.setRootEntity(sceneRoot);
Please find a screenshot of the error attached here.
I am trying to use this snippet inside my Adobe Illustrator plugin.
After breaking the exception, I get this.
Can anyone guide me here?
Am I missing any dll references or something? -
Thanks for replying!
This is the code,
int argc = 0; QApplication* _Application = static_cast<QApplication *>(QApplication::instance()); _Application = new QApplication(argc, 0, true); view = new Window(); // view is a global object of Window type. view->setPosition(10, 100); Qt3DCore::QAspectEngine engine; Qt3DInput::QInputAspect *inputAspect = new Qt3DInput::QInputAspect(); engine.registerAspect(new Qt3DRender::QRenderAspect()); engine.registerAspect(inputAspect); QVariantMap data; data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(view))); data.insert(QStringLiteral("eventSource"), QVariant::fromValue(view)); engine.setData(data); // Root entity Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity(); //// Scene Camera Qt3DCore::QCamera *basicCamera = new Qt3DCore::QCamera(sceneRoot); basicCamera->setProjectionType(Qt3DCore::QCameraLens::PerspectiveProjection); basicCamera->setAspectRatio(view->width() / view->height()); basicCamera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f)); basicCamera->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f)); basicCamera->setPosition(QVector3D(0.0f, 3.5f, 25.0f)); basicCamera->setNearPlane(0.001f); basicCamera->setFarPlane(10000.0f); // For camera controls inputAspect->setCamera(basicCamera); //// Forward Renderer FrameGraph Qt3DRender::QFrameGraph *frameGraphComponent = new Qt3DRender::QFrameGraph(sceneRoot); Qt3DRender::QForwardRenderer *forwardRenderer = new Qt3DRender::QForwardRenderer(); forwardRenderer->setCamera(basicCamera); forwardRenderer->setClearColor(Qt::black); frameGraphComponent->setActiveFrameGraph(forwardRenderer); sceneRoot->addComponent(frameGraphComponent); // Scene loader Qt3DCore::QEntity *sceneLoaderEntity = new Qt3DCore::QEntity(sceneRoot); Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(sceneLoaderEntity); SceneWalker sceneWalker(sceneLoader); QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, &sceneWalker, &SceneWalker::onStatusChanged); sceneLoaderEntity->addComponent(sceneLoader); std::string url = GetURL(); QString source = "file:///"; source.append(url.c_str()); // This gives us a url to a local file eg, file:///C:/work/qt/model.dae QUrl sourceFileName = source; if (sourceFileName.isEmpty()) return 0; sceneLoader->setSource(sourceFileName); engine.setRootEntity(sceneRoot); view->show();
Looks like
sceneRoot
is a non-null pointer to a valid object. -
- You are leaking memory like a bandit
- The QApplication constructor is invalid, please see the warning here: http://doc.qt.io/qt-5/qapplication.html#QApplication
replace
int argc = 0; QApplication* _Application = static_cast<QApplication *>(QApplication::instance()); _Application = new QApplication(argc, 0, true);
with
char arg0[] = "programName"; char* argv[] = { &arg0[0], NULL }; int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1; QApplication the_application(argc, &argv[0]);
-
I think that sceneRoot must be not the parent of the frame graph.
You have forgot to set a rendering surface.
The FrameGraph root node must be a QRenderSettings//// Forward Renderer FrameGraph Qt3DRender::QFrameGraph *frameGraphComponent = new Qt3DRender::QFrameGraph(sceneRoot); Qt3DRender::QForwardRenderer *forwardRenderer = new Qt3DRender::QForwardRenderer(); forwardRenderer->setCamera(basicCamera); forwardRenderer->setClearColor(Qt::black); frameGraphComponent->setActiveFrameGraph(forwardRenderer); sceneRoot->addComponent(frameGraphComponent);
to:
//// Forward Renderer FrameGraph Qt3DRender::QRenderSettings *frameGraphComponent = new Qt3DRender::QRenderSettings(); //not set the parent Qt3DRender::QForwardRenderer *forwardRenderer = new Qt3DRender::QForwardRenderer(); forwardRenderer->setCamera(basicCamera); forwardRenderer->setClearColor(Qt::black); forwardRenderer->surface(view); //add a surface for the rendering loop frameGraphComponent->setActiveFrameGraph(forwardRenderer); sceneRoot->addComponent(frameGraphComponent);
There are me be a mistake when you set the root entity.
In the Qt3DWindow the root entity is set like follow:157 void Qt3DWindow::showEvent(QShowEvent *e) 158 { 159 if (!m_initialized) { 160 if (m_userRoot != nullptr) 161 m_userRoot->setParent(m_root); 162 163 m_root->addComponent(m_renderSettings); 164 m_root->addComponent(m_inputSettings); 165 m_aspectEngine->setRootEntity(Qt3DCore::QEntityPtr(m_root)); 166 167 m_initialized = true; 168 } 169 170 QWindow::showEvent(e); 171 }
https://code.woboq.org/qt5/qt3d/src/extras/defaults/qt3dwindow.cpp.html
Me be change you code to:
engine.setRootEntity(Qt3DCore::QEntityPtr(sceneRoot));