Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyframe undo that would cause crash or double undo in some cases (issue #1557) #1629

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void Editor::backup(const QString& undoText)
}
}

void Editor::backup(int backupLayer, int backupFrame, const QString& undoText)
bool Editor::backup(int backupLayer, int backupFrame, const QString& undoText)
{
while (mBackupList.size() - 1 > mBackupIndex && !mBackupList.empty())
{
Expand Down Expand Up @@ -236,6 +236,7 @@ void Editor::backup(int backupLayer, int backupFrame, const QString& undoText)
mBackupList.append(element);
mBackupIndex++;
}
else { return false; }
}
else if (layer->type() == Layer::VECTOR)
{
Expand All @@ -254,6 +255,7 @@ void Editor::backup(int backupLayer, int backupFrame, const QString& undoText)
mBackupList.append(element);
mBackupIndex++;
}
else { return false; }
}
else if (layer->type() == Layer::SOUND)
{
Expand All @@ -280,12 +282,15 @@ void Editor::backup(int backupLayer, int backupFrame, const QString& undoText)
mBackupIndex++;
}
}
else { return false; }
}
}

updateAutoSaveCounter();

emit updateBackup();

return true;
}

void Editor::sanitizeBackupElementsAfterLayerDeletion(int layerIndex)
Expand Down Expand Up @@ -410,20 +415,23 @@ void Editor::undo()
if (lastBackupElement->type() == BackupElement::BITMAP_MODIF)
{
BackupBitmapElement* lastBackupBitmapElement = static_cast<BackupBitmapElement*>(lastBackupElement);
backup(lastBackupBitmapElement->layer, lastBackupBitmapElement->frame, "NoOp");
mBackupIndex--;
if (backup(lastBackupBitmapElement->layer, lastBackupBitmapElement->frame, "NoOp")) {
mBackupIndex--;
}
}
if (lastBackupElement->type() == BackupElement::VECTOR_MODIF)
{
BackupVectorElement* lastBackupVectorElement = static_cast<BackupVectorElement*>(lastBackupElement);
backup(lastBackupVectorElement->layer, lastBackupVectorElement->frame, "NoOp");
mBackupIndex--;
if (backup(lastBackupVectorElement->layer, lastBackupVectorElement->frame, "NoOp")) {
mBackupIndex--;
}
}
if (lastBackupElement->type() == BackupElement::SOUND_MODIF)
{
BackupSoundElement* lastBackupSoundElement = static_cast<BackupSoundElement*>(lastBackupElement);
backup(lastBackupSoundElement->layer, lastBackupSoundElement->frame, "NoOp");
mBackupIndex--;
if (backup(lastBackupSoundElement->layer, lastBackupSoundElement->frame, "NoOp")) {
mBackupIndex--;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/interface/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Editor : public QObject
void swapLayers(int i, int j);

void backup(const QString& undoText);
void backup(int layerNumber, int frameNumber, const QString& undoText);
bool backup(int layerNumber, int frameNumber, const QString& undoText);
/**
* Restores integrity of the backup elements after a layer has been deleted.
* Removes backup elements affecting the deleted layer and adjusts the layer
Expand Down