some bullshit to fix potential crash
This commit is contained in:
@@ -1 +1 @@
|
|||||||
/home/anon/sda/Personal/Repos/anm2ed/out/build/linux-debug/compile_commands.json
|
/home/anon/sda/Personal/Repos/anm2ed/out/build/linux-release/compile_commands.json
|
||||||
+62
-2
@@ -1,5 +1,6 @@
|
|||||||
#include "document.hpp"
|
#include "document.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -26,6 +27,63 @@ namespace anm2ed
|
|||||||
return it->second;
|
return it->second;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restored_snapshot_sanitize(Document& document)
|
||||||
|
{
|
||||||
|
auto& reference = document.reference;
|
||||||
|
auto& documentAnm2 = document.anm2;
|
||||||
|
auto& selection = document.frames.selection;
|
||||||
|
|
||||||
|
auto animationCount = (int)documentAnm2.animations.items.size();
|
||||||
|
if (animationCount <= 0)
|
||||||
|
{
|
||||||
|
reference = {};
|
||||||
|
selection.clear();
|
||||||
|
document.frameTime = 0.0f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reference.animationIndex < 0 || reference.animationIndex >= animationCount)
|
||||||
|
reference.animationIndex = std::clamp(reference.animationIndex, 0, animationCount - 1);
|
||||||
|
|
||||||
|
auto item = documentAnm2.item_get(reference.animationIndex, reference.itemType, reference.itemID);
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
reference.itemType = ROOT;
|
||||||
|
reference.itemID = -1;
|
||||||
|
item = documentAnm2.item_get(reference.animationIndex, reference.itemType, reference.itemID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
reference.frameIndex = -1;
|
||||||
|
selection.clear();
|
||||||
|
document.frameTime = 0.0f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto frameCount = (int)item->frames.size();
|
||||||
|
for (auto it = selection.begin(); it != selection.end();)
|
||||||
|
{
|
||||||
|
if (*it < 0 || *it >= frameCount)
|
||||||
|
it = selection.erase(it);
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frameCount <= 0)
|
||||||
|
{
|
||||||
|
reference.frameIndex = -1;
|
||||||
|
document.frameTime = 0.0f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reference.frameIndex < 0 || reference.frameIndex >= frameCount)
|
||||||
|
reference.frameIndex = selection.empty() ? std::clamp(reference.frameIndex, 0, frameCount - 1)
|
||||||
|
: *selection.begin();
|
||||||
|
|
||||||
|
document.frameTime = item->frame_time_from_index_get(reference.frameIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Document(Anm2& anm2, const std::filesystem::path& path)
|
Document::Document(Anm2& anm2, const std::filesystem::path& path)
|
||||||
@@ -390,7 +448,8 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Document::undo()
|
void Document::undo()
|
||||||
{
|
{
|
||||||
snapshots.undo();
|
if (!snapshots.undo()) return;
|
||||||
|
restored_snapshot_sanitize(*this);
|
||||||
toasts.push(std::vformat(localize.get(TOAST_UNDO), std::make_format_args(message)));
|
toasts.push(std::vformat(localize.get(TOAST_UNDO), std::make_format_args(message)));
|
||||||
logger.info(std::vformat(localize.get(TOAST_UNDO, anm2ed::ENGLISH), std::make_format_args(message)));
|
logger.info(std::vformat(localize.get(TOAST_UNDO, anm2ed::ENGLISH), std::make_format_args(message)));
|
||||||
change(Document::ALL);
|
change(Document::ALL);
|
||||||
@@ -398,7 +457,8 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Document::redo()
|
void Document::redo()
|
||||||
{
|
{
|
||||||
snapshots.redo();
|
if (!snapshots.redo()) return;
|
||||||
|
restored_snapshot_sanitize(*this);
|
||||||
toasts.push(std::vformat(localize.get(TOAST_REDO), std::make_format_args(message)));
|
toasts.push(std::vformat(localize.get(TOAST_REDO), std::make_format_args(message)));
|
||||||
logger.info(std::vformat(localize.get(TOAST_REDO, anm2ed::ENGLISH), std::make_format_args(message)));
|
logger.info(std::vformat(localize.get(TOAST_REDO, anm2ed::ENGLISH), std::make_format_args(message)));
|
||||||
change(Document::ALL);
|
change(Document::ALL);
|
||||||
|
|||||||
@@ -1132,10 +1132,24 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLeftPressed) frame_change_apply({.scaleX = step}, anm2::SUBTRACT);
|
if (isSelectedNullRect)
|
||||||
if (isRightPressed) frame_change_apply({.scaleX = step}, anm2::ADD);
|
{
|
||||||
if (isUpPressed) frame_change_apply({.scaleY = step}, anm2::SUBTRACT);
|
if (isLeftPressed)
|
||||||
if (isDownPressed) frame_change_apply({.scaleY = step}, anm2::ADD);
|
frame_change_apply({.positionX = step * 0.5f, .scaleX = step}, anm2::SUBTRACT);
|
||||||
|
if (isRightPressed)
|
||||||
|
frame_change_apply({.positionX = step * 0.5f, .scaleX = step}, anm2::ADD);
|
||||||
|
if (isUpPressed)
|
||||||
|
frame_change_apply({.positionY = step * 0.5f, .scaleY = step}, anm2::SUBTRACT);
|
||||||
|
if (isDownPressed)
|
||||||
|
frame_change_apply({.positionY = step * 0.5f, .scaleY = step}, anm2::ADD);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isLeftPressed) frame_change_apply({.scaleX = step}, anm2::SUBTRACT);
|
||||||
|
if (isRightPressed) frame_change_apply({.scaleX = step}, anm2::ADD);
|
||||||
|
if (isUpPressed) frame_change_apply({.scaleY = step}, anm2::SUBTRACT);
|
||||||
|
if (isDownPressed) frame_change_apply({.scaleY = step}, anm2::ADD);
|
||||||
|
}
|
||||||
|
|
||||||
if (isToolDuring)
|
if (isToolDuring)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -491,7 +491,6 @@ namespace anm2ed::imgui
|
|||||||
if (!animation) return;
|
if (!animation) return;
|
||||||
if (auto item = animation->item_get(reference.itemType, reference.itemID))
|
if (auto item = animation->item_get(reference.itemType, reference.itemID))
|
||||||
{
|
{
|
||||||
document.snapshot(localize.get(EDIT_PASTE_FRAMES));
|
|
||||||
std::set<int> indices{};
|
std::set<int> indices{};
|
||||||
std::string errorString{};
|
std::string errorString{};
|
||||||
int insertIndex = (int)item->frames.size();
|
int insertIndex = (int)item->frames.size();
|
||||||
|
|||||||
+6
-2
@@ -53,22 +53,26 @@ namespace anm2ed
|
|||||||
redoStack.clear();
|
redoStack.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snapshots::undo()
|
bool Snapshots::undo()
|
||||||
{
|
{
|
||||||
if (auto snapshot = undoStack.pop())
|
if (auto snapshot = undoStack.pop())
|
||||||
{
|
{
|
||||||
redoStack.push(current);
|
redoStack.push(current);
|
||||||
current = *snapshot;
|
current = *snapshot;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snapshots::redo()
|
bool Snapshots::redo()
|
||||||
{
|
{
|
||||||
if (auto snapshot = redoStack.pop())
|
if (auto snapshot = redoStack.pop())
|
||||||
{
|
{
|
||||||
undoStack.push(current);
|
undoStack.push(current);
|
||||||
current = *snapshot;
|
current = *snapshot;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snapshots::reset()
|
void Snapshots::reset()
|
||||||
|
|||||||
+2
-2
@@ -63,8 +63,8 @@ namespace anm2ed
|
|||||||
|
|
||||||
Snapshot* get();
|
Snapshot* get();
|
||||||
void push(const Snapshot&);
|
void push(const Snapshot&);
|
||||||
void undo();
|
bool undo();
|
||||||
void redo();
|
bool redo();
|
||||||
void reset();
|
void reset();
|
||||||
void apply_limit();
|
void apply_limit();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user