From 25391fe765f72c0c079f5589afc717bb8fed25a8 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Fri, 7 Nov 2025 00:11:14 +0100 Subject: [PATCH] try to catch / handle Gif decoder OOM gracefully ... by adding an exception handler that will catch OOM inside decoder.alloc(). not tested yet. --- wled00/image_loader.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wled00/image_loader.cpp b/wled00/image_loader.cpp index 5ba7af0a..6ad0dc2d 100644 --- a/wled00/image_loader.cpp +++ b/wled00/image_loader.cpp @@ -131,7 +131,18 @@ byte renderImageToSegment(Segment &seg) { decoder.setFileReadCallback(fileReadCallback); decoder.setFileReadBlockCallback(fileReadBlockCallback); decoder.setFileSizeCallback(fileSizeCallback); +#if __cpp_exceptions // use exception handler if we can (some targets don't support exceptions) + try { +#endif decoder.alloc(); // WLEDMM this function may throw out-of memory and cause a crash +#if __cpp_exceptions + } catch (...) { // if we arrive here, the decoder has thrown an OOM exception + gifDecodeFailed = true; + errorFlag = ERR_NORAM_PX; + USER_PRINTLN("\nGIF decoder out of memory. I'm going to shoot myself now.\n"); + return IMAGE_ERROR_DECODER_ALLOC; + } +#endif DEBUG_PRINTLN(F("Starting decoding")); int derr = 0;