Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Prevent overlapping saves and autosaves

manongjohna36213c8a823
diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cpp
index 68144a819..198155867 100644
--- a/toonz/sources/toonz/iocommand.cpp
+++ b/toonz/sources/toonz/iocommand.cpp
@@ -1517,6 +1517,11 @@ bool IoCmd::saveScene(const TFilePath &path, int flags) {
CleanupParameters oldCP(*cp);
cp->assign(&CleanupParameters::GlobalParameters);
+ // Must wait for current save to finish, just in case
+ while (TApp::instance()->isSaveInProgress())
+ ;
+
+ TApp::instance()->setSaveInProgress(true);
try {
scene->save(scenePath, xsheet);
} catch (const TSystemException &se) {
@@ -1524,6 +1529,7 @@ bool IoCmd::saveScene(const TFilePath &path, int flags) {
} catch (...) {
DVGui::error(QObject::tr("Couldn't save %1").arg(toQString(scenePath)));
}
+ TApp::instance()->setSaveInProgress(false);
cp->assign(&oldCP);
@@ -1584,6 +1590,7 @@ bool IoCmd::saveScene(int flags) {
} else {
TFilePath fp = scene->getScenePath();
// salva la scena con il nome fp. se fp esiste gia' lo sovrascrive
+ // NOTE: saveScene already check saveInProgress
return saveScene(fp, SILENTLY_OVERWRITE | flags);
}
}
@@ -1732,13 +1739,20 @@ bool IoCmd::saveLevel(TXshSimpleLevel *sl) {
bool IoCmd::saveAll(int flags) {
// try to save as much as possible
// if anything is wrong, return false
+ // NOTE: saveScene already check saveInProgress
bool result = saveScene(flags);
TApp *app = TApp::instance();
ToonzScene *scene = app->getCurrentScene()->getScene();
bool untitled = scene->isUntitled();
SceneResources resources(scene, 0);
+ // Must wait for current save to finish, just in case
+ while (TApp::instance()->isSaveInProgress())
+ ;
+
+ TApp::instance()->setSaveInProgress(true);
resources.save(scene->getScenePath());
+ TApp::instance()->setSaveInProgress(false);
resources.updatePaths();
// for update title bar
@@ -1759,7 +1773,13 @@ void IoCmd::saveNonSceneFiles() {
ToonzScene *scene = app->getCurrentScene()->getScene();
bool untitled = scene->isUntitled();
SceneResources resources(scene, 0);
+ // Must wait for current save to finish, just in case
+ while (TApp::instance()->isSaveInProgress())
+ ;
+
+ TApp::instance()->setSaveInProgress(true);
resources.save(scene->getScenePath());
+ TApp::instance()->setSaveInProgress(false);
if (untitled) scene->setUntitled();
resources.updatePaths();
diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cpp
index 17c273159..86b1d3aac 100644
--- a/toonz/sources/toonz/tapp.cpp
+++ b/toonz/sources/toonz/tapp.cpp
@@ -103,6 +103,7 @@ TApp::TApp()
, m_mainWindow(0)
, m_autosaveTimer(0)
, m_autosaveSuspended(false)
+ , m_saveInProgress(false)
, m_isStarting(false)
, m_isPenCloseToTablet(false) {
m_currentScene = new TSceneHandle();
@@ -707,6 +708,8 @@ void TApp::autosave() {
} else
m_autosaveSuspended = false;
+ if (m_saveInProgress) return;
+
DVGui::ProgressDialog pb(
"Autosaving scene..." + toQString(scene->getScenePath()), 0, 0, 1);
pb.show();
diff --git a/toonz/sources/toonz/tapp.h b/toonz/sources/toonz/tapp.h
index ec5695a1a..a6f092f4e 100644
--- a/toonz/sources/toonz/tapp.h
+++ b/toonz/sources/toonz/tapp.h
@@ -86,6 +86,7 @@ class TApp final : public QObject,
int m_autosavePeriod; // minutes
bool m_autosaveSuspended;
+ bool m_saveInProgress;
QTimer *m_autosaveTimer;
TApp();
@@ -205,6 +206,9 @@ public:
XsheetViewer *getCurrentXsheetViewer() const { return m_xsheetViewer; }
+ bool isSaveInProgress() { return m_saveInProgress; }
+ void setSaveInProgress(bool inProgress) { m_saveInProgress = inProgress; }
+
protected:
bool eventFilter(QObject *obj, QEvent *event) override;