mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-06 06:58:15 +00:00
Fix deleting docs from memory when "keep closed docs alive" is disabled & the backup on disk is enabled
This commit is contained in:
parent
f0e60d2068
commit
e3f28acf9e
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -22,8 +22,6 @@ namespace app {
|
||||
ClosedDocs::ClosedDocs(const Preferences& pref)
|
||||
: m_done(false)
|
||||
{
|
||||
CLOSEDOC_TRACE("CLOSEDOC: Init");
|
||||
|
||||
if (pref.general.dataRecovery())
|
||||
m_dataRecoveryPeriodMSecs = int(1000.0*60.0*pref.general.dataRecoveryPeriod());
|
||||
else
|
||||
@ -33,6 +31,10 @@ ClosedDocs::ClosedDocs(const Preferences& pref)
|
||||
m_keepClosedDocAliveForMSecs = int(1000.0*60.0*pref.general.keepClosedSpriteOnMemoryFor());
|
||||
else
|
||||
m_keepClosedDocAliveForMSecs = 0;
|
||||
|
||||
CLOSEDOC_TRACE("CLOSEDOC: Init",
|
||||
"dataRecoveryPeriod", m_dataRecoveryPeriodMSecs,
|
||||
"keepClosedDocs", m_keepClosedDocAliveForMSecs);
|
||||
}
|
||||
|
||||
ClosedDocs::~ClosedDocs()
|
||||
@ -123,15 +125,20 @@ void ClosedDocs::backgroundThread()
|
||||
|
||||
for (auto it=m_docs.begin(); it != m_docs.end(); ) {
|
||||
const ClosedDoc& closedDoc = *it;
|
||||
auto doc = closedDoc.doc;
|
||||
|
||||
base::tick_t diff = now - closedDoc.timestamp;
|
||||
if (diff >= m_keepClosedDocAliveForMSecs) {
|
||||
if (m_dataRecoveryPeriodMSecs == 0 ||
|
||||
closedDoc.doc->isFullyBackedUp()) {
|
||||
if (// If we backup process is disabled
|
||||
m_dataRecoveryPeriodMSecs == 0 ||
|
||||
// Or this document doesn't need a backup (e.g. an unmodified document)
|
||||
!doc->needsBackup() ||
|
||||
// Or the document already has the backup done
|
||||
doc->isFullyBackedUp()) {
|
||||
// Finally delete the document (this is the place where we
|
||||
// delete all documents created/loaded by the user)
|
||||
CLOSEDOC_TRACE("CLOSEDOC: [BG] Delete doc", closedDoc.doc);
|
||||
delete closedDoc.doc;
|
||||
CLOSEDOC_TRACE("CLOSEDOC: [BG] Delete doc", doc);
|
||||
delete doc;
|
||||
it = m_docs.erase(it);
|
||||
}
|
||||
else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2019 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -97,15 +97,20 @@ void BackupObserver::onRemoveDocument(Doc* doc)
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
base::remove_from_container(m_documents, doc);
|
||||
}
|
||||
if (m_config->keepEditedSpriteDataFor > 0 &&
|
||||
doc->needsBackup() &&
|
||||
if (doc->needsBackup() &&
|
||||
// If the backup is disabled, we don't need it (e.g. when the
|
||||
// document is destroyed from a script with Sprite:close(), the
|
||||
// backup is disabled)
|
||||
!doc->inhibitBackup()) {
|
||||
// If m_config->keepEditedSpriteDataFor == 0 we add the document
|
||||
// in m_closedDocs list anyway so we call markAsBackedUp(), and
|
||||
// then it's deleted from ClosedDocs::backgroundThread()
|
||||
|
||||
TRACE("RECO: Adding to CLOSEDOC %p\n", doc);
|
||||
m_closedDocs.push_back(doc);
|
||||
}
|
||||
else {
|
||||
TRACE("RECO: Removing doc %p from session\n", doc);
|
||||
m_session->removeDocument(doc);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2019 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -39,6 +39,8 @@
|
||||
#include <limits>
|
||||
#include <map>
|
||||
|
||||
#define DOC_TRACE(...) // TRACEARGS
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace base;
|
||||
@ -61,10 +63,12 @@ Doc::Doc(Sprite* sprite)
|
||||
sprites().add(sprite);
|
||||
|
||||
updateOSColorSpace(false);
|
||||
DOC_TRACE("DOC: New", this);
|
||||
}
|
||||
|
||||
Doc::~Doc()
|
||||
{
|
||||
DOC_TRACE("DOC: Deleting", this);
|
||||
removeFromContext();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user