diff --git a/ui/zenoedit/dock/ztabdockwidget.cpp b/ui/zenoedit/dock/ztabdockwidget.cpp index 56d20b09c7..32322ccce4 100644 --- a/ui/zenoedit/dock/ztabdockwidget.cpp +++ b/ui/zenoedit/dock/ztabdockwidget.cpp @@ -119,7 +119,7 @@ QWidget* ZTabDockWidget::widget() const return m_tabWidget; } -void ZTabDockWidget::testCleanupGL() +void ZTabDockWidget::cleanupView() { for (int i = 0; i < m_tabWidget->count(); i++) { @@ -127,7 +127,7 @@ void ZTabDockWidget::testCleanupGL() if (DockContent_View* pDis = qobject_cast(wid)) { DisplayWidget* pWid = pDis->getDisplayWid(); if (pWid) - pWid->testCleanUp(); + pWid->cleanupView(); } } } diff --git a/ui/zenoedit/dock/ztabdockwidget.h b/ui/zenoedit/dock/ztabdockwidget.h index 91ade1f1a6..89a5d07da1 100644 --- a/ui/zenoedit/dock/ztabdockwidget.h +++ b/ui/zenoedit/dock/ztabdockwidget.h @@ -46,7 +46,7 @@ class ZTabDockWidget : public QDockWidget void onPrimitiveSelected(const std::unordered_set& primids); void onUpdateViewport(const QString& action); void updateLights(); - void testCleanupGL(); + void cleanupView(); static PANEL_TYPE title2Type(const QString &title); diff --git a/ui/zenoedit/viewport/displaywidget.cpp b/ui/zenoedit/viewport/displaywidget.cpp index dbe2b70626..5b83f270e0 100644 --- a/ui/zenoedit/viewport/displaywidget.cpp +++ b/ui/zenoedit/viewport/displaywidget.cpp @@ -84,10 +84,12 @@ void DisplayWidget::initRecordMgr() [=](int frameid) { zeno::log_info("frame {} has been recorded", frameid); }); } -void DisplayWidget::testCleanUp() +void DisplayWidget::cleanupView() { if (m_glView) - m_glView->testCleanUp(); + m_glView->cleanUpView(); + else + m_optixView->cleanupView(); } void DisplayWidget::cleanUpScene() diff --git a/ui/zenoedit/viewport/displaywidget.h b/ui/zenoedit/viewport/displaywidget.h index f31186e8f6..5aaa263850 100644 --- a/ui/zenoedit/viewport/displaywidget.h +++ b/ui/zenoedit/viewport/displaywidget.h @@ -28,7 +28,7 @@ class DisplayWidget : public QWidget QSize sizeHint() const override; Zenovis* getZenoVis() const; void runAndRecord(const VideoRecInfo& info); - void testCleanUp(); + void cleanupView(); void cleanUpScene(); void beforeRun(); void afterRun(); diff --git a/ui/zenoedit/viewport/optixviewport.cpp b/ui/zenoedit/viewport/optixviewport.cpp index cb85615c84..47c4f80c2c 100644 --- a/ui/zenoedit/viewport/optixviewport.cpp +++ b/ui/zenoedit/viewport/optixviewport.cpp @@ -331,6 +331,11 @@ void OptixWorker::onCleanUpScene() m_zenoVis->cleanUpScene(); } +void OptixWorker::onCleanUpView() +{ + m_zenoVis->cleanupView(); +} + void OptixWorker::onSetBackground(bool bShowBg) { auto& ud = zeno::getSession().userData(); @@ -427,6 +432,7 @@ ZOptixViewport::ZOptixViewport(QWidget* parent) connect(this, &ZOptixViewport::sig_modifyLightData, m_worker, &OptixWorker::onModifyLightData); connect(this, &ZOptixViewport::sig_updateCameraProp, m_worker, &OptixWorker::onUpdateCameraProp); connect(this, &ZOptixViewport::sig_cleanUpScene, m_worker, &OptixWorker::onCleanUpScene); + connect(this, &ZOptixViewport::sig_cleanUpView, m_worker, &OptixWorker::onCleanUpView); connect(this, &ZOptixViewport::sig_setBackground, m_worker, &OptixWorker::onSetBackground); connect(this, &ZOptixViewport::sig_setdata_on_optix_thread, m_worker, &OptixWorker::onSetData); @@ -505,6 +511,11 @@ void ZOptixViewport::cleanUpScene() emit sig_cleanUpScene(); } +void ZOptixViewport::cleanupView() +{ + emit sig_cleanUpView(); +} + void ZOptixViewport::modifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString name, UI_VECTYPE skipParam) { emit sig_modifyLightData(pos, scale, rotate, color, intensity, name, skipParam); diff --git a/ui/zenoedit/viewport/optixviewport.h b/ui/zenoedit/viewport/optixviewport.h index d7ef63a06b..e9864b38bb 100644 --- a/ui/zenoedit/viewport/optixviewport.h +++ b/ui/zenoedit/viewport/optixviewport.h @@ -42,6 +42,7 @@ public slots: void onModifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString nodename, UI_VECTYPE skipParam); void onUpdateCameraProp(float aperture, float disPlane, UI_VECTYPE skipParam = UI_VECTYPE()); void onCleanUpScene(); + void onCleanUpView(); void onSetBackground(bool bShowBg); void onSetData(float, float, float, bool, bool); @@ -84,6 +85,7 @@ class ZOptixViewport : public QWidget void setSlidFeq(int feq); void modifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString name, UI_VECTYPE skipParam); void cleanUpScene(); + void cleanupView(); zenovis::ZOptixCameraSettingInfo getdata_from_optix_thread(); void setdata_on_optix_thread(zenovis::ZOptixCameraSettingInfo value); @@ -107,6 +109,7 @@ class ZOptixViewport : public QWidget void sig_modifyLightData(UI_VECTYPE pos, UI_VECTYPE scale, UI_VECTYPE rotate, UI_VECTYPE color, float intensity, QString name, UI_VECTYPE skipParam); void sig_updateCameraProp(float aperture, float disPlane, UI_VECTYPE skipParam = UI_VECTYPE()); void sig_cleanUpScene(); + void sig_cleanUpView(); void sig_setBackground(bool bShowBg); void sig_setdata_on_optix_thread(float, float, float, bool, bool); diff --git a/ui/zenoedit/viewport/viewportwidget.cpp b/ui/zenoedit/viewport/viewportwidget.cpp index db0866c991..d43bcc9375 100644 --- a/ui/zenoedit/viewport/viewportwidget.cpp +++ b/ui/zenoedit/viewport/viewportwidget.cpp @@ -133,6 +133,12 @@ void ViewportWidget::testCleanUp() m_fakeTrans.reset(); } +void ViewportWidget::cleanUpView() +{ + if (m_zenovis) + m_zenovis->cleanupView(); +} + namespace { struct OpenGLProcAddressHelper { inline static QGLContext *ctx; diff --git a/ui/zenoedit/viewport/viewportwidget.h b/ui/zenoedit/viewport/viewportwidget.h index 3a40259b1f..af8e7a55af 100644 --- a/ui/zenoedit/viewport/viewportwidget.h +++ b/ui/zenoedit/viewport/viewportwidget.h @@ -25,6 +25,7 @@ class ViewportWidget : public QGLWidget ViewportWidget(QWidget* parent = nullptr); ~ViewportWidget(); void testCleanUp(); + void cleanUpView(); void initializeGL() override; void resizeGL(int nx, int ny) override; void paintGL() override; diff --git a/ui/zenoedit/viewport/zenovis.cpp b/ui/zenoedit/viewport/zenovis.cpp index 2b879b210e..423e87da16 100644 --- a/ui/zenoedit/viewport/zenovis.cpp +++ b/ui/zenoedit/viewport/zenovis.cpp @@ -120,6 +120,16 @@ void Zenovis::cleanUpScene() pScene->cleanUpScene(); } +void Zenovis::cleanupView() +{ + if (!session) + return; + + auto pScene = session->get_scene(); + ZASSERT_EXIT(pScene); + pScene->cleanupView(); +} + void Zenovis::startPlay(bool bPlaying) { m_playing = bPlaying; diff --git a/ui/zenoedit/viewport/zenovis.h b/ui/zenoedit/viewport/zenovis.h index e1c0c1977c..5062249232 100644 --- a/ui/zenoedit/viewport/zenovis.h +++ b/ui/zenoedit/viewport/zenovis.h @@ -54,6 +54,7 @@ public slots: void setLoopPlaying(bool enable); bool isLoopPlaying(); void cleanUpScene(); + void cleanupView(); //private: void doFrameUpdate(); diff --git a/ui/zenoedit/zenomainwindow.cpp b/ui/zenoedit/zenomainwindow.cpp index 4b611cf62d..bd2211e2d5 100644 --- a/ui/zenoedit/zenomainwindow.cpp +++ b/ui/zenoedit/zenomainwindow.cpp @@ -1387,16 +1387,8 @@ void ZenoMainWindow::closeEvent(QCloseEvent *event) //clean up opengl components. auto docks = findChildren(QString(), Qt::FindDirectChildrenOnly); - for (ZTabDockWidget *pDock : docks) { - pDock->close(); - try { - //pDock->testCleanupGL(); - } catch (...) { - //QString errMsg = QString::fromLatin1(e.what()); - int j; - j = 0; - } - //delete pDock; + for (ZTabDockWidget* pDock : docks) { + pDock->cleanupView(); } // trigger destroy event diff --git a/zenovis/include/zenovis/RenderEngine.h b/zenovis/include/zenovis/RenderEngine.h index a5c0ad58b9..7ce48ce0b5 100644 --- a/zenovis/include/zenovis/RenderEngine.h +++ b/zenovis/include/zenovis/RenderEngine.h @@ -16,6 +16,7 @@ struct RenderEngine { virtual void draw(bool record) = 0; virtual void update() = 0; virtual void cleanupOptix() = 0; + virtual void cleanupWhenExit() = 0; virtual ~RenderEngine() = default; }; diff --git a/zenovis/include/zenovis/Scene.h b/zenovis/include/zenovis/Scene.h index 9f7a6adbd0..2d379bc035 100644 --- a/zenovis/include/zenovis/Scene.h +++ b/zenovis/include/zenovis/Scene.h @@ -44,6 +44,7 @@ struct Scene : zeno::disable_copy { void draw(bool record); bool loadFrameObjects(int frameid); void cleanUpScene(); + void cleanupView(); void switchRenderEngine(std::string const &name); std::vector record_frame_offline(int hdrSize = 1, int rgbComps = 3); bool cameraFocusOnNode(std::string const &nodeid, zeno::vec3f ¢er, float &radius); diff --git a/zenovis/src/Scene.cpp b/zenovis/src/Scene.cpp index 347814a3ae..11df211415 100644 --- a/zenovis/src/Scene.cpp +++ b/zenovis/src/Scene.cpp @@ -48,6 +48,17 @@ Scene::Scene() switchRenderEngine("bate"); } +void Scene::cleanupView() +{ + if (!renderMan) + return; + + RenderEngine* pEngine = renderMan->getEngine(); + if (pEngine) { + pEngine->cleanupWhenExit(); + } +} + void Scene::cleanUpScene() { if (objectsMan) diff --git a/zenovis/src/bate/RenderEngineBate.cpp b/zenovis/src/bate/RenderEngineBate.cpp index 2a67d741ac..9a324ffd91 100644 --- a/zenovis/src/bate/RenderEngineBate.cpp +++ b/zenovis/src/bate/RenderEngineBate.cpp @@ -95,6 +95,10 @@ struct RenderEngineBate : RenderEngine { void cleanupOptix() override { } + + void cleanupWhenExit() override { + + } }; static auto definer = RenderManager::registerRenderEngine("bate"); diff --git a/zenovis/src/optx/RenderEngineOptx.cpp b/zenovis/src/optx/RenderEngineOptx.cpp index 4e8542328c..b6ba4c66c2 100644 --- a/zenovis/src/optx/RenderEngineOptx.cpp +++ b/zenovis/src/optx/RenderEngineOptx.cpp @@ -1395,6 +1395,10 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy { void cleanupOptix() override { } + + void cleanupWhenExit() override { + + } }; static auto definer = RenderManager::registerRenderEngine("optx"); diff --git a/zenovis/src/zhxx/RenderEngineZhxx.cpp b/zenovis/src/zhxx/RenderEngineZhxx.cpp index 8ee8ed1621..ac3a5c1913 100644 --- a/zenovis/src/zhxx/RenderEngineZhxx.cpp +++ b/zenovis/src/zhxx/RenderEngineZhxx.cpp @@ -126,6 +126,10 @@ struct RenderEngineZhxx : RenderEngine, zeno::disable_copy { void cleanupOptix() override { } + + void cleanupWhenExit() override { + + } }; static auto definer = RenderManager::registerRenderEngine("zhxx");