Skip to content

Commit

Permalink
Merge pull request #1629 from aeroc7/master
Browse files Browse the repository at this point in the history
Fix keyframe undo that would cause crash or double undo in some cases (issue #1557)
  • Loading branch information
candyface authored Apr 18, 2021
2 parents 28ba695 + d8bc388 commit 2935790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit 2935790

Please sign in to comment.