From 376cce57ab83a0b035383003337d56ad242dacbf Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 21 Nov 2026 22:35:54 -0500 Subject: [PATCH] Fix AutomationEventList uninitialized unload --- include/AutomationEventList.hpp | 24 +++++++++++------------- tests/raylib_cpp_test.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/include/AutomationEventList.hpp b/include/AutomationEventList.hpp index 0f9b9d62..f17c66aa 100644 --- a/include/AutomationEventList.hpp +++ b/include/AutomationEventList.hpp @@ -25,7 +25,7 @@ class AutomationEventList : public ::AutomationEventList { * * @param fileName The file path to load the automation events list from. */ - AutomationEventList(const char* fileName) { Load(fileName); } + AutomationEventList(const char* fileName) : ::AutomationEventList{} { Load(fileName); } AutomationEventList(const AutomationEventList&) = delete; @@ -44,6 +44,7 @@ class AutomationEventList : public ::AutomationEventList { GETTER(AutomationEvent*, Events, events) AutomationEventList& operator=(const ::AutomationEventList& other) { + Unload(); set(other); return *this; } @@ -66,7 +67,7 @@ class AutomationEventList : public ::AutomationEventList { } /** - * Load audio stream (to stream raw audio pcm data) + * Load automation events list from file, unloading any existing events. * * @throws raylib::RaylibException Throws if the AutomationEventList failed to load. */ @@ -79,26 +80,23 @@ class AutomationEventList : public ::AutomationEventList { } /** - * Update audio stream buffers with data + * Unload automation events list from memory. */ void Unload() { if (!IsValid()) { return; } -// The function signature of UnloadAutomationEventList() changes from raylib 5.0. -#if RAYLIB_VERSION_MAJOR == 5 -#if RAYLIB_VERSION_MINOR == 0 - ::UnloadAutomationEventList(this); -#elif RAYLIB_VERSION_MINOR >= 1 - ::UnloadAutomationEventList(*this); -#endif -#else ::UnloadAutomationEventList(*this); -#endif + capacity = 0; + count = 0; + events = nullptr; } - bool IsValid() { return events != nullptr; } + /** + * Check if the automation events list has been loaded. + */ + bool IsValid() const { return events != nullptr; } bool Export(const char* fileName) { return ::ExportAutomationEventList(*this, fileName); } diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index d2539e85..b0cbff40 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -3,6 +3,7 @@ #include "raylib-assert.h" // clang-format on #include +#include #include int main(int argc, char* argv[]) { @@ -174,6 +175,34 @@ int main(int argc, char* argv[]) { Assert(passed, "Expected to have a RaylibException to be thrown"); } + // AutomationEventList + { + raylib::AutomationEventList list; + Assert(list.IsValid(), "Expected empty automation event list to be valid"); + AssertEqual(list.GetCount(), 0); + Assert(list.GetCapacity() > 0, "Expected automation event list to have capacity"); + + raylib::AutomationEventList moved; + moved = std::move(list); + Assert(moved.IsValid(), "Expected moved automation event list to be valid"); + AssertNot(list.IsValid(), "Expected moved-from automation event list to be invalid"); + + // raylib returns an empty list when the file is missing. + bool threw = false; + try { + raylib::AutomationEventList missing("notfound.rae"); + Assert(missing.IsValid(), "Expected missing file to give an empty list"); + AssertEqual(missing.GetCount(), 0); + } catch (raylib::RaylibException& error) { + error.TraceLog(LOG_INFO); + threw = true; + } + AssertNot(threw, "Expected no RaylibException for a missing automation file"); + + moved.Unload(); + AssertNot(moved.IsValid(), "Expected unloaded automation event list to be invalid"); + } + // Load FileData { raylib::FileData file(path + "/resources/weird.wav");