From 79634df52252e51b494bbbdb11d372dcb123e6b6 Mon Sep 17 00:00:00 2001 From: Taksh Date: Wed, 22 Apr 2026 17:44:58 +0530 Subject: [PATCH] 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