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