Masterwork From Distant Lands
ActivePublic

Authored by dkazakov on Aug 11 2016, 2:36 PM.
diff --git a/libs/ui/KisDocument.cpp b/libs/ui/KisDocument.cpp
index b486f90..b35bae6 100644
--- a/libs/ui/KisDocument.cpp
+++ b/libs/ui/KisDocument.cpp
@@ -2378,6 +2378,8 @@ void KisDocument::setFileProgressUpdater(const QString &text)
void KisDocument::clearFileProgressUpdater()
{
+ ENTER_FUNCTION() << ppVar(d->suppressProgress) << ppVar(d->progressUpdater);
+
if (!d->suppressProgress && d->progressUpdater) {
disconnect(KisPart::instance()->currentMainwindow(), SIGNAL(sigProgressCanceled()), this, SIGNAL(sigProgressCanceled()));
disconnect(this, SIGNAL(sigProgress(int)), KisPart::instance()->currentMainwindow(), SLOT(slotProgress(int)));
diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp
index dd2087e..4b3e532 100644
--- a/libs/ui/KisMainWindow.cpp
+++ b/libs/ui/KisMainWindow.cpp
@@ -894,6 +894,13 @@ void KisMainWindow::slotSaveCompleted()
}
}
+bool KisMainWindow::hackIsSaving() const
+{
+ StdLockableWrapper<QMutex> wrapper(&d->savingEntryMutex);
+ std::unique_lock<StdLockableWrapper<QMutex>> l(wrapper, std::try_to_lock);
+ return !l.owns_lock();
+}
+
bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool silent, int specialOutputFlag)
{
if (!document) {
@@ -1806,9 +1813,11 @@ void KisMainWindow::viewFullscreen(bool fullScreen)
void KisMainWindow::slotProgress(int value)
{
- qApp->processEvents();
+ StdLockableWrapper<QMutex> wrapper(&d->progressMutex);
+ std::unique_lock<StdLockableWrapper<QMutex>> l(wrapper, std::try_to_lock);
+ if (!l.owns_lock()) return;
- if (!d->progressMutex.tryLock()) return;
+ qApp->processEvents();
dbgUI << "KisMainWindow::slotProgress" << value;
if (value <= -1 || value >= 100) {
@@ -1823,7 +1832,6 @@ void KisMainWindow::slotProgress(int value)
d->progressCancel = 0;
}
d->firstTime = true;
- d->progressMutex.unlock();
return;
}
if (d->firstTime || !d->progress) {
@@ -1866,8 +1874,6 @@ void KisMainWindow::slotProgress(int value)
d->progress->setValue(value);
}
qApp->processEvents();
-
- d->progressMutex.unlock();
}
void KisMainWindow::slotProgressCanceled()
diff --git a/libs/ui/KisMainWindow.h b/libs/ui/KisMainWindow.h
index 08d1fce..dd68b6c 100644
--- a/libs/ui/KisMainWindow.h
+++ b/libs/ui/KisMainWindow.h
@@ -142,6 +142,17 @@ public:
QStringList showOpenFileDialog();
+ /**
+ * Shows if the main window is saving anything right now. If the
+ * user presses Ctrl+W too fast, then the document can be close
+ * before the saving is completed. I'm not sure if it is fixable
+ * in any way without avoiding using porcessEvents()
+ * everywhere (DK)
+ *
+ * Don't use it unless you have no option.
+ */
+ bool hackIsSaving() const;
+
Q_SIGNALS:
/**
diff --git a/libs/ui/KisPart.cpp b/libs/ui/KisPart.cpp
index 8db0b68..d3917ac 100644
--- a/libs/ui/KisPart.cpp
+++ b/libs/ui/KisPart.cpp
@@ -269,6 +269,16 @@ void KisPart::removeView(KisView *view)
{
if (!view) return;
+ /**
+ * HACK ALERT: we check here explicitly if the document (or main
+ * window), is saving the stuff. If we close the
+ * document *before* the saving is completed, a crash
+ * will happen.
+ */
+ if (view->mainWindow()->hackIsSaving()) {
+ return;
+ }
+
emit sigViewRemoved(view);
QPointer<KisDocument> doc = view->document();
@@ -283,6 +293,8 @@ void KisPart::removeView(KisView *view)
}
}
if (!found) {
+ ENTER_FUNCTION();
+
removeDocument(doc);
}
}
dkazakov edited the content of this paste. (Show Details)Aug 11 2016, 2:36 PM
dkazakov changed the title of this paste from untitled to Masterwork From Distant Lands.