Skip to content

Commit

Permalink
Prevent overlapping saves and autosaves
Browse files Browse the repository at this point in the history
  • Loading branch information
manongjohn committed Jan 27, 2024
1 parent 2bbedf4 commit a36213c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions toonz/sources/toonz/iocommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,13 +1517,19 @@ 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) {
DVGui::warning(QString::fromStdWString(se.getMessage()));
} catch (...) {
DVGui::error(QObject::tr("Couldn't save %1").arg(toQString(scenePath)));
}
TApp::instance()->setSaveInProgress(false);

cp->assign(&oldCP);

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions toonz/sources/toonz/tapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions toonz/sources/toonz/tapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class TApp final : public QObject,

int m_autosavePeriod; // minutes
bool m_autosaveSuspended;
bool m_saveInProgress;
QTimer *m_autosaveTimer;

TApp();
Expand Down Expand Up @@ -205,6 +206,9 @@ class TApp final : public QObject,

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;

Expand Down

0 comments on commit a36213c

Please sign in to comment.