From 460fe47fce83cb14b415631a81e0ef690461b764 Mon Sep 17 00:00:00 2001 From: lovyan03 <42724151+lovyan03@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:40:04 +0900 Subject: [PATCH] Fixed a crash problem when not enough memory is available. (for ESP32) --- src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index 3667b39a..784e2032 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -425,10 +425,13 @@ namespace lgfx len = (limit << 1) <= length ? limit : length; if (limit <= 256) limit <<= 1; auto dmabuf = _flip_buffer.getBuffer(len * bytes); + if (dmabuf == nullptr) { + break; + } param->fp_copy(dmabuf, 0, len, param); writeBytes(dmabuf, len * bytes, true, true); } while (length -= len); - return; + if (length == 0) return; } /// ESP32-C3 で HIGHPART を使用すると異常動作するため分岐する; @@ -532,10 +535,12 @@ namespace lgfx { if (false == use_dma && length < 1024) { - use_dma = true; auto buf = _flip_buffer.getBuffer(length); - memcpy(buf, data, length); - data = buf; + if (buf) { + memcpy(buf, data, length); + data = buf; + use_dma = true; + } } if (use_dma) {