Save files whole or not at all, and keep a render's sounds alive

file_text_save writes a temporary file beside its target, checks every write
and the close, then renames it over the target. A full disk or quota error
no longer leaves a truncated save reported as a success (which then deleted
the autosave). Documents, autosaves, settings and PNGs all save through it.

A recording copies each trigger sound once, so a library reloaded mid-render
leaves its audio mix nothing freed to read. A recording's finish reports
whether its output was made, which animation_record now returns in place of
whether the path existed. A PNG sequence format without a placeholder
numbers each frame after its name instead of writing one file over and over,
and pixel buffers are sized in integers (a float count could run short).
This commit is contained in:
shweet committed 2026-11-22 19:46:22 -05:00
1 parent 71b0ef683b
commit 068d189e6a
11 files changed
+98 -46

No files matched your search

+16
View File
@@ -2,6 +2,7 @@
#include "asset_store.h"
#include "audio_data.h"
#include "file.h"
#include "font.h"
#include "friends.h"
#include "icon.h"
@@ -135,3 +136,18 @@ TEST_CASE("Embedded resources load")
for (auto& font : FONTS)
CHECK(font->size > 0);
}
TEST_CASE("a save replaces its file whole, or leaves it as it was")
{
auto path = std::filesystem::temp_directory_path() / "anm2ed_save_test.txt";
auto text = std::string{};
REQUIRE(file_text_save(path, "first"));
CHECK(file_text_save(path, "second"));
CHECK(file_text_load(path, &text));
CHECK(text == "second");
CHECK_FALSE(file_text_save(path / "inside_a_file.txt", "third"));
CHECK(file_text_load(path, &text));
CHECK(text == "second");
CHECK_FALSE(std::filesystem::exists(path.string() + ".tmp"));
std::filesystem::remove(path);
}
+25 -1
View File
@@ -6,7 +6,6 @@
#include <algorithm>
#include <cstdlib>
#include <format>
#include <fstream>
#include "audio.h"
@@ -133,6 +132,31 @@ TEST_CASE("a recorded spritesheet holds every frame")
golden_image_check("spin_sheet.png");
}
TEST_CASE("a PNG sequence without a placeholder numbers each frame")
{
RenderFixture fixture("spin.anm2");
if (!fixture.gl.is_valid())
{
MESSAGE("skipped: no OpenGL context");
return;
}
auto directory = OUTPUT_DIR / "spin_sequence";
std::filesystem::remove_all(directory);
RecorderOptions options{.type = RENDER_PNGS,
.path = directory,
.format = "spin.png",
.start = 0,
.end = fixture.animation->frameNum - 1,
.animationFps = fixture.document->model.info.fps,
.fps = fixture.document->model.info.fps};
REQUIRE(animation_record(options, *fixture.canvas, *fixture.shader, *fixture.document, *fixture.animation,
fixture.bounds, SCALE, BACKGROUND, true));
auto count = std::ranges::distance(std::filesystem::directory_iterator(directory));
CHECK(count == fixture.animation->frameNum);
CHECK(std::filesystem::exists(directory / "spin_000000.png"));
}
TEST_CASE("animation layers draw their child animations")
{
RenderFixture fixture("nested.anm2");