diff --git a/toonz/sources/toonz/filmstrip.cpp b/toonz/sources/toonz/filmstrip.cpp index 37f06dde..50810b19 100644 --- a/toonz/sources/toonz/filmstrip.cpp +++ b/toonz/sources/toonz/filmstrip.cpp @@ -486,14 +486,19 @@ void FilmstripFrames::hideEvent(QHideEvent *) { // active viewer change disconnect(app, SIGNAL(activeViewerChanged()), this, SLOT(getViewer())); - // if the level strip is floating during shutting down Tahoma2D - // it can cause a crash disconnecting from the viewer which was already - // destroyed. - if (m_viewer && m_viewer->isValid()) { - disconnect(m_viewer, SIGNAL(onZoomChanged()), this, SLOT(update())); - disconnect(m_viewer, SIGNAL(refreshNavi()), this, SLOT(update())); - m_viewer = nullptr; - } + disconnectViewer(); +} + +//----------------------------------------------------------------------------- + +void FilmstripFrames::disconnectViewer() { + if (!m_viewer) return; + + disconnect(m_viewer, SIGNAL(onZoomChanged()), this, SLOT(update())); + disconnect(m_viewer, SIGNAL(refreshNavi()), this, SLOT(update())); + disconnect(m_viewer, SIGNAL(viewerDestructing()), this, + SLOT(disconnectViewer())); + m_viewer = nullptr; } //----------------------------------------------------------------------------- @@ -501,10 +506,7 @@ void FilmstripFrames::hideEvent(QHideEvent *) { void FilmstripFrames::getViewer() { bool viewerChanged = false; if (m_viewer != TApp::instance()->getActiveViewer()) { - if (m_viewer) { - disconnect(m_viewer, SIGNAL(onZoomChanged()), this, SLOT(update())); - disconnect(m_viewer, SIGNAL(refreshNavi()), this, SLOT(update())); - } + disconnectViewer(); viewerChanged = true; } @@ -513,6 +515,8 @@ void FilmstripFrames::getViewer() { if (m_viewer && viewerChanged) { connect(m_viewer, SIGNAL(onZoomChanged()), this, SLOT(update())); connect(m_viewer, SIGNAL(refreshNavi()), this, SLOT(update())); + connect(m_viewer, SIGNAL(viewerDestructing()), this, + SLOT(disconnectViewer())); update(); } } @@ -1675,7 +1679,7 @@ void Filmstrip::updateCurrentLevelComboItem() { } for (int i = 0; i < m_levels.size(); i++) { - TXshSimpleLevel* tempLevel = m_levels[i]; + TXshSimpleLevel *tempLevel = m_levels[i]; std::wstring currName = currentLevel->getName(); int type = tempLevel->getType(); if (type < 0 || type > MESH_XSHLEVEL) break; diff --git a/toonz/sources/toonz/filmstrip.h b/toonz/sources/toonz/filmstrip.h index fb3cb97d..95d0c232 100644 --- a/toonz/sources/toonz/filmstrip.h +++ b/toonz/sources/toonz/filmstrip.h @@ -172,6 +172,7 @@ protected slots: void comboBoxToggled(bool); void navigatorToggled(bool); void levelSelected(int); + void disconnectViewer(); private: // QSS Properties diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index c707f7f5..3f28e1c5 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -852,6 +852,8 @@ SceneViewer::~SceneViewer() { int ret = l_contexts.erase(m_currentContext); if (ret) TGLDisplayListsManager::instance()->releaseContext(m_currentContext); + + emit viewerDestructing(); } //------------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h index 21649d2e..644c67bb 100644 --- a/toonz/sources/toonz/sceneviewer.h +++ b/toonz/sources/toonz/sceneviewer.h @@ -484,7 +484,7 @@ public slots: void onContextAboutToBeDestroyed(); void onNewStopMotionImageReady(); void onStopMotionLiveViewStopped(); - void onPreferenceChanged(const QString& prefName); + void onPreferenceChanged(const QString &prefName); signals: @@ -498,6 +498,7 @@ signals: void refreshNavi(); // for updating the titlebar void previewToggled(); + void viewerDestructing(); }; // Functions