From 0d52695aa9f425a3dd051fc0845118666c467475 Mon Sep 17 00:00:00 2001 From: Thomas COIN Date: Thu, 29 Oct 2020 14:15:27 +0100 Subject: [PATCH] It is strongly recommended to check the new allocated pointer is not null --- FAQ-#3.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FAQ-#3.md b/FAQ-#3.md index ba1f9f3..51808f7 100644 --- a/FAQ-#3.md +++ b/FAQ-#3.md @@ -39,12 +39,17 @@ void setup() { ... } -void PixelCountChanged(uint16_t newCount) { +bool PixelCountChanged(uint16_t newCount) { if (strip != NULL) { delete strip; // delete the previous dynamically created strip } strip = new NeoPixelBus(newCount, Pin); // and recreate with new count + if (strip == NULL) { + Serial.println("OUT OF MEMORY"); + return false; + } strip->Begin(); + return true; } void loop() {