diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index c789211b4..4d0c58069 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -166,6 +166,7 @@ class PinManagerClass { }; //playlist.cpp +void unloadPlaylist(); void loadPlaylist(JsonObject playlistObject); void handlePlaylist(); diff --git a/wled00/led.cpp b/wled00/led.cpp index 32e38f7d7..9f887667e 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -30,6 +30,7 @@ void toggleOnOff() { briLast = bri; bri = 0; + unloadPlaylist(); } } diff --git a/wled00/playlist.cpp b/wled00/playlist.cpp index 911e26929..b294fdef7 100644 --- a/wled00/playlist.cpp +++ b/wled00/playlist.cpp @@ -74,9 +74,19 @@ void serializePlaylist() { } */ +void unloadPlaylist() { + if (playlistEntries != nullptr) { + delete[] playlistEntries; + playlistEntries = nullptr; + } + currentPlaylist = playlistIndex = -1; + playlistLen = playlistEntryDur = 0; +} + void loadPlaylist(JsonObject playlistObj) { - if (playlistEntries != nullptr) {delete[] playlistEntries; playlistEntries = nullptr;} - currentPlaylist = playlistIndex = -1; playlistEntryDur = 0; + + unloadPlaylist(); + JsonArray presets = playlistObj["ps"]; playlistLen = presets.size(); if (playlistLen == 0) return;