Skip to content

Commit

Permalink
Merge pull request #1904 from zenustech/zeno2-fixbug
Browse files Browse the repository at this point in the history
add cleanupWhenExit interface for engine. and call them when exit.
  • Loading branch information
zhouhang95 authored Apr 22, 2024
2 parents b6b568b + 01d6239 commit 184c1a9
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ui/zenoedit/dock/ztabdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ QWidget* ZTabDockWidget::widget() const
return m_tabWidget;
}

void ZTabDockWidget::testCleanupGL()
void ZTabDockWidget::cleanupView()
{
for (int i = 0; i < m_tabWidget->count(); i++)
{
QWidget* wid = m_tabWidget->widget(0);
if (DockContent_View* pDis = qobject_cast<DockContent_View*>(wid)) {
DisplayWidget* pWid = pDis->getDisplayWid();
if (pWid)
pWid->testCleanUp();
pWid->cleanupView();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/zenoedit/dock/ztabdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ZTabDockWidget : public QDockWidget
void onPrimitiveSelected(const std::unordered_set<std::string>& primids);
void onUpdateViewport(const QString& action);
void updateLights();
void testCleanupGL();
void cleanupView();

static PANEL_TYPE title2Type(const QString &title);

Expand Down
6 changes: 4 additions & 2 deletions ui/zenoedit/viewport/displaywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ui/zenoedit/viewport/displaywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions ui/zenoedit/viewport/optixviewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ui/zenoedit/viewport/optixviewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions ui/zenoedit/viewport/viewportwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/viewport/viewportwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions ui/zenoedit/viewport/zenovis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/viewport/zenovis.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public slots:
void setLoopPlaying(bool enable);
bool isLoopPlaying();
void cleanUpScene();
void cleanupView();

//private:
void doFrameUpdate();
Expand Down
12 changes: 2 additions & 10 deletions ui/zenoedit/zenomainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,16 +1387,8 @@ void ZenoMainWindow::closeEvent(QCloseEvent *event)
//clean up opengl components.

auto docks = findChildren<ZTabDockWidget *>(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
Expand Down
1 change: 1 addition & 0 deletions zenovis/include/zenovis/RenderEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions zenovis/include/zenovis/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> record_frame_offline(int hdrSize = 1, int rgbComps = 3);
bool cameraFocusOnNode(std::string const &nodeid, zeno::vec3f &center, float &radius);
Expand Down
11 changes: 11 additions & 0 deletions zenovis/src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions zenovis/src/bate/RenderEngineBate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ struct RenderEngineBate : RenderEngine {
void cleanupOptix() override {

}

void cleanupWhenExit() override {

}
};

static auto definer = RenderManager::registerRenderEngine<RenderEngineBate>("bate");
Expand Down
4 changes: 4 additions & 0 deletions zenovis/src/optx/RenderEngineOptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,10 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy {
void cleanupOptix() override {

}

void cleanupWhenExit() override {

}
};

static auto definer = RenderManager::registerRenderEngine<RenderEngineOptx>("optx");
Expand Down
4 changes: 4 additions & 0 deletions zenovis/src/zhxx/RenderEngineZhxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ struct RenderEngineZhxx : RenderEngine, zeno::disable_copy {
void cleanupOptix() override {

}

void cleanupWhenExit() override {

}
};

static auto definer = RenderManager::registerRenderEngine<RenderEngineZhxx>("zhxx");
Expand Down

0 comments on commit 184c1a9

Please sign in to comment.