From 4db1cfafb685e566e688bcec0868ab9d7ffa8e2a Mon Sep 17 00:00:00 2001 From: shweet Date: Fri, 22 May 2026 09:31:05 -0400 Subject: [PATCH] the source of the random crashes?! --- src/log.cpp | 22 +++++++++++++++++++--- src/snapshots.cpp | 24 +++++++++++++++++++++++- src/snapshots.hpp | 2 ++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 143363c..6d7e2e8 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -8,6 +8,7 @@ #include "file.hpp" #include "path.hpp" #include "sdl.hpp" +#include "strings.hpp" #include "time.hpp" #if _WIN32 @@ -24,8 +25,23 @@ namespace anm2ed void Logger::write_raw(const std::string& message) { std::lock_guard lock(mutex); - std::println("{}", message); - if (!logPath.empty()) file::write_string(logPath, message + '\n', "ab"); + try + { + std::println("{}", message); + } + catch (...) + { + } + if (!logPath.empty()) + { + try + { + file::write_string(logPath, message + '\n', "ab"); + } + catch (...) + { + } + } } void Logger::write(const Level level, const std::string& message) @@ -144,7 +160,7 @@ namespace anm2ed Logger::Logger() { open(path()); - info("Initializing Anm2Ed"); + info(std::format("Initializing {}", localize.get(LABEL_APPLICATION_NAME, ENGLISH))); } Logger::~Logger() diff --git a/src/snapshots.cpp b/src/snapshots.cpp index 098fb73..c8e0fb7 100644 --- a/src/snapshots.cpp +++ b/src/snapshots.cpp @@ -8,6 +8,28 @@ namespace anm2ed { int SnapshotStack::maxSize = snapshots::MAX; + Snapshot Snapshot::stack_copy_get() const + { + Snapshot out{}; + out.playback = playback; + out.animation = animation; + out.event = event; + out.frames = frames; + out.items = items; + out.layer = layer; + out.merge = merge; + out.null = null; + out.region = region; + out.sound = sound; + out.spritesheet = spritesheet; + out.textures = textures; + out.anm2 = anm2; + out.reference = reference; + out.frameTime = frameTime; + out.message = message; + return out; + } + bool SnapshotStack::is_empty() { return stack.empty(); } void SnapshotStack::push(const Snapshot& snapshot) @@ -18,7 +40,7 @@ namespace anm2ed return; } if ((int)stack.size() >= maxSize) stack.pop_front(); - stack.push_back(snapshot); + stack.push_back(snapshot.stack_copy_get()); } std::optional SnapshotStack::pop() diff --git a/src/snapshots.hpp b/src/snapshots.hpp index a1776cd..3f4f2df 100644 --- a/src/snapshots.hpp +++ b/src/snapshots.hpp @@ -38,6 +38,8 @@ namespace anm2ed Reference reference{}; float frameTime{}; std::string message = snapshots::ACTION; + + Snapshot stack_copy_get() const; }; class SnapshotStack