Fix scene switching flipbook crash

This commit is contained in:
manongjohn 2022-04-13 13:13:32 -04:00
parent 91a511ffa0
commit e004e3800e
5 changed files with 24 additions and 0 deletions

View file

@ -42,6 +42,7 @@ public:
emit sceneChanged();
if (setDirty) setDirtyFlag(true);
}
void notifySceneSwitching() { emit sceneSwitching(); }
void notifySceneSwitched() {
emit sceneSwitched();
setDirtyFlag(false);
@ -76,6 +77,7 @@ public slots:
}
signals:
void sceneSwitching();
void sceneSwitched();
void sceneChanged();
void castChanged();

View file

@ -236,6 +236,10 @@ FlipBook::FlipBook(QWidget *parent, QString viewerTitle,
m_previewUpdateTimer.setSingleShot(true);
TSceneHandle *sceneHandle = TApp::instance()->getCurrentScene();
ret = ret && connect(sceneHandle, SIGNAL(sceneSwitching()), this,
SLOT(onSceneSwitching()));
ret = ret && connect(parentWidget(), SIGNAL(closeButtonPressed()), this,
SLOT(onCloseButtonPressed()));
ret = ret && connect(parentWidget(), SIGNAL(doubleClick(QMouseEvent *)), this,
@ -549,6 +553,10 @@ void FlipBook::loadImages() {
//=============================================================================
void FlipBook::clearImages() { reset(); }
//=============================================================================
bool FlipBook::canAppend() {
// Images can be appended if:
// a) There is a name (in particular, an extension) representing currently
@ -1862,6 +1870,9 @@ void FlipBook::reset() {
else
PreviewFxManager::instance()->detach(this);
m_snd = 0;
m_xl = 0;
m_levelNames.clear();
m_levels.clear();
m_framesCount = 0;
@ -2264,3 +2275,7 @@ FlipBook *viewFile(const TFilePath &path, int from, int to, int step,
}
//-----------------------------------------------------------------------------
void FlipBook::onSceneSwitching() {
if (m_xl || m_isPreviewFx) reset();
}

View file

@ -299,6 +299,7 @@ public slots:
void saveImages();
void loadImages();
void clearImages();
void performFxUpdate();
void regenerate();
@ -306,6 +307,8 @@ public slots:
void clonePreview();
void freezePreview();
void unfreezePreview();
void onSceneSwitching();
};
// utility

View file

@ -307,6 +307,9 @@ void ImageViewer::contextMenuEvent(QContextMenuEvent *event) {
menu->addAction(action);
action->setParent(m_flipbook);
action = menu->addAction(tr("Clear Images"));
connect(action, SIGNAL(triggered()), m_flipbook, SLOT(clearImages()));
menu->addSeparator();
}

View file

@ -23,6 +23,7 @@ ToonzScene *TSceneHandle::getScene() const { return m_scene; }
void TSceneHandle::setScene(ToonzScene *scene) {
if (m_scene == scene) return;
emit sceneSwitching();
delete m_scene;
m_scene = scene;
if (m_scene) emit sceneSwitched();