From 3e6432172f8ccfbe7413aca594f3dd1e0b2c49d1 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Thu, 11 Sep 2025 19:23:45 +1000 Subject: [PATCH 1/2] Add resource bundle tests Adapted from Andrew Cain's test_bundles.cpp --- .../src/test/unit_tests/unit_test_bundles.cpp | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 coresdk/src/test/unit_tests/unit_test_bundles.cpp diff --git a/coresdk/src/test/unit_tests/unit_test_bundles.cpp b/coresdk/src/test/unit_tests/unit_test_bundles.cpp new file mode 100644 index 00000000..fbdefcd5 --- /dev/null +++ b/coresdk/src/test/unit_tests/unit_test_bundles.cpp @@ -0,0 +1,62 @@ +/** + * Bundle unit tests + */ + +#include "catch.hpp" + +#include "bundles.h" +#include "resources.h" +#include "audio.h" +#include "images.h" +#include "timers.h" +#include "text.h" + +using namespace splashkit_lib; + +// Log pointers of freed resources +void free_notification(void *resource) +{ + UNSCOPED_INFO("Freeing: " << resource); +} + +TEST_CASE("Load and free resource bundle", "[load_resource_bundle][free_resource_bundle]") +{ + register_free_notifier(&free_notification); + + /** + * Load test resource bundle containing: + * ANIM,WalkingScript,kermit.txt + * BITMAP,FrogBmp,frog.png, 73, 105, 4, 4, 16 + * FONT,hara,hara.ttf + * SOUND,error,error.wav + * MUSIC,background,energize_my_mind.mod + * TIMER,my timer + * BUNDLE,blah,blah.txt + */ + load_resource_bundle("test", "test.txt"); + + // Confirm bundle and its resources are loaded + REQUIRE(has_resource_bundle("test")); + REQUIRE(has_animation_script("WalkingScript")); + REQUIRE(has_bitmap("FrogBmp")); + REQUIRE(has_font("hara")); + REQUIRE(has_sound_effect("error")); + REQUIRE(has_music("background")); + REQUIRE(has_timer("my timer")); + REQUIRE(has_resource_bundle("blah")); + REQUIRE(has_bitmap("ufo")); + REQUIRE(has_resource_bundle("test")); + + // Free bundle and confirm resources are freed + free_resource_bundle("test"); + + REQUIRE_FALSE(has_resource_bundle("test")); + REQUIRE_FALSE(has_animation_script("WalkingScript")); + REQUIRE_FALSE(has_bitmap("FrogBmp")); + REQUIRE_FALSE(has_font("hara")); + REQUIRE_FALSE(has_sound_effect("error")); + REQUIRE_FALSE(has_music("background")); + REQUIRE_FALSE(has_timer("my timer")); + REQUIRE_FALSE(has_resource_bundle("blah")); + REQUIRE_FALSE(has_bitmap("ufo")); +} \ No newline at end of file From ab19b0a4cd90ac800d4292599933922f7c2496c0 Mon Sep 17 00:00:00 2001 From: dijidiji Date: Thu, 11 Sep 2025 21:32:53 +1000 Subject: [PATCH 2/2] Fix bundled bitmaps not being unloaded When loading, the IMAGE_RESOURCE case had the following check: if ( ! has_resource_bundle(line_name) ) return; This would always return (because it was checking resource bundles rather than bitmaps), bitmaps to be loaded but never be added to the list of bundled resources. This in turn resulted in free_resource_bundle never freeing that resource. --- coresdk/src/coresdk/bundles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coresdk/src/coresdk/bundles.cpp b/coresdk/src/coresdk/bundles.cpp index 6d5e41e1..e04002f4 100644 --- a/coresdk/src/coresdk/bundles.cpp +++ b/coresdk/src/coresdk/bundles.cpp @@ -141,7 +141,7 @@ namespace splashkit_lib break; case IMAGE_RESOURCE: rb_load_bitmap(line_name, line_path); - if ( ! has_resource_bundle(line_name) ) return; + if ( ! has_bitmap(line_name) ) return; break; case FONT_RESOURCE: load_font(line_name, line_path);