restore revious presetToSave in case that mutex acquisition fails

This commit is contained in:
Frank
2025-12-29 21:09:04 +01:00
parent d505dcc6a8
commit 91dc9a5b5a

View File

@@ -312,6 +312,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
}
DEBUG_PRINT(F("Saving preset (")); DEBUG_PRINT(index); DEBUG_PRINT(F(") ")); DEBUG_PRINTLN(saveName);
auto oldpresetToSave = presetToSave; // for recovery in case that esp32SemTake(presetFileMux) fails
presetToSave = index;
playlistSave = false;
@@ -330,6 +331,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
// WLEDMM Acquire file mutex before writing presets.json, to prevent presets.json corruption
if (esp32SemTake(presetFileMux, 2500) != pdTRUE) {
USER_PRINTLN(F("savePreset(): preset file busy, cannot write"));
presetToSave = oldpresetToSave;
return; // early exit, no change
}