From 9407e84ffa8d01a27ab85c1395d24556843e2763 Mon Sep 17 00:00:00 2001 From: Dominic Clark Date: Sun, 1 Oct 2017 21:01:38 +0100 Subject: [PATCH] Stop some autosave crashes (#3841) --- include/MainWindow.h | 7 ------- include/RemotePlugin.h | 33 +++++++++++++++++++++++++++++++++ src/gui/MainWindow.cpp | 21 +++++++-------------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index 1a58f868c02..7ba2ac63079 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -249,11 +249,4 @@ private slots: } ; -class AutoSaveThread : public QThread -{ - Q_OBJECT -public: - void run(); -} ; - #endif diff --git a/include/RemotePlugin.h b/include/RemotePlugin.h index b3ac4b676f1..2d811487587 100644 --- a/include/RemotePlugin.h +++ b/include/RemotePlugin.h @@ -621,6 +621,11 @@ class EXPORT RemotePluginBase fetchAndProcessNextMessage(); } } + + static bool isMainThreadWaiting() + { + return waitDepthCounter() > 0; + } #endif virtual bool processMessage( const message & _m ) = 0; @@ -657,6 +662,14 @@ class EXPORT RemotePluginBase private: +#ifndef BUILD_REMOTE_PLUGIN_CLIENT + static int & waitDepthCounter() + { + static int waitDepth = 0; + return waitDepth; + } +#endif + #ifdef SYNC_WITH_SHM_FIFO shmFifo * m_in; shmFifo * m_out; @@ -1089,6 +1102,26 @@ RemotePluginBase::message RemotePluginBase::waitForMessage( _busy_waiting = QThread::currentThread() == QCoreApplication::instance()->thread(); } + + struct WaitDepthCounter + { + WaitDepthCounter( int & depth, bool busy ) : + m_depth( depth ), + m_busy( busy ) + { + if( m_busy ) { ++m_depth; } + } + + ~WaitDepthCounter() + { + if( m_busy ) { --m_depth; } + } + + int & m_depth; + bool m_busy; + }; + + WaitDepthCounter wdc( waitDepthCounter(), _busy_waiting ); #endif while( !isInvalid() ) { diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 9bb4bfea667..b91fe3ef2fa 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -54,6 +54,7 @@ #include "PluginView.h" #include "ProjectJournal.h" #include "ProjectNotes.h" +#include "RemotePlugin.h" #include "SetupDialog.h" #include "SideBar.h" #include "SongEditor.h" @@ -1535,14 +1536,14 @@ void MainWindow::browseHelp() void MainWindow::autoSave() { if( !Engine::getSong()->isExporting() && + !Engine::getSong()->isLoadingProject() && + !RemotePluginBase::isMainThreadWaiting() && !QApplication::mouseButtons() && - ( ConfigManager::inst()->value( "ui", - "enablerunningautosave" ).toInt() || - ! Engine::getSong()->isPlaying() ) ) + ( ConfigManager::inst()->value( "ui", + "enablerunningautosave" ).toInt() || + ! Engine::getSong()->isPlaying() ) ) { - AutoSaveThread * ast = new AutoSaveThread(); - connect( ast, SIGNAL( finished() ), ast, SLOT( deleteLater() ) ); - ast->start(); + Engine::getSong()->saveProjectFile(ConfigManager::inst()->recoveryFile()); autoSaveTimerReset(); // Reset timer } else @@ -1554,11 +1555,3 @@ void MainWindow::autoSave() } } } - - - - -void AutoSaveThread::run() -{ - Engine::getSong()->saveProjectFile(ConfigManager::inst()->recoveryFile()); -}