From 79634df52252e51b494bbbdb11d372dcb123e6b6 Mon Sep 17 00:00:00 2001 From: Taksh Date: Wed, 22 Apr 2026 17:44:58 +0530 Subject: [PATCH 1/2] Reject non-positive duration in saveGif to avoid empty-frames crash When saveGif is called with duration <= 0, the main recording loop never runs and the frames array stays empty. _generateGlobalPalette then reads frames[0].length, producing a cryptic TypeError. Validate duration > 0 up front with a clear error, matching the existing type checks. Fixes #8710 --- src/image/loading_displaying.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/image/loading_displaying.js b/src/image/loading_displaying.js index f257b2a0d3..369b137b70 100644 --- a/src/image/loading_displaying.js +++ b/src/image/loading_displaying.js @@ -303,6 +303,9 @@ p5.prototype.saveGif = async function( if (typeof duration !== 'number') { throw TypeError('Duration parameter must be a number'); } + if (duration <= 0) { + throw new Error('Duration parameter must be a positive number'); + } // extract variables for more comfortable use const delay = (options && options.delay) || 0; // in seconds From 32f012b018e183e66da0a5a2235f6348955c461a Mon Sep 17 00:00:00 2001 From: Taksh Date: Thu, 28 May 2026 06:24:59 +0530 Subject: [PATCH 2/2] Update duration check to return silently instead of throwing --- src/image/loading_displaying.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image/loading_displaying.js b/src/image/loading_displaying.js index 369b137b70..15327ce233 100644 --- a/src/image/loading_displaying.js +++ b/src/image/loading_displaying.js @@ -304,7 +304,7 @@ p5.prototype.saveGif = async function( throw TypeError('Duration parameter must be a number'); } if (duration <= 0) { - throw new Error('Duration parameter must be a positive number'); + return; } // extract variables for more comfortable use