From d505dcc6a80e02eddefac55365d73ccd3121d896 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 29 Dec 2025 21:02:06 +0100 Subject: [PATCH] fix presets.json corruption, part 2: protect deletePresets deletePreset() also needs to acquire presetFileMux before writing. --- wled00/presets.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wled00/presets.cpp b/wled00/presets.cpp index c87f2cf2..2ef0bfd7 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -358,8 +358,16 @@ void savePreset(byte index, const char* pname, JsonObject sObj) } void deletePreset(byte index) { + // WLEDMM Acquire file mutex before writing presets.json, to prevent presets.json corruption + if (esp32SemTake(presetFileMux, 2500) != pdTRUE) { + USER_PRINTLN(F("deletePreset(): preset file busy, cannot write")); + return; // early exit, no change + } + StaticJsonDocument<24> empty; writeObjectToFileUsingId(getFileName(), index, &empty); + + esp32SemGive(presetFileMux); // Release file mutex presetsModifiedTime = toki.second(); //unix time updateFSInfo(); } \ No newline at end of file