From dac769bd44b55dde0f07f706797312672f9ef4b1 Mon Sep 17 00:00:00 2001 From: Ady0333 Date: Sat, 17 Jan 2026 14:46:02 +0530 Subject: [PATCH] Fix preload functions hanging when assets fail without error callback Always call _decrementPreload() in error handlers regardless of whether a failureCallback was provided. Previously, failed preloads without callbacks would leave _preloadCount > 0 forever, preventing setup() from running. Signed-off-by: Ady0333 --- src/image/loading_displaying.js | 6 +++--- src/io/files.js | 13 +++++++++---- src/typography/loading_displaying.js | 6 ++++-- src/webgl/loading.js | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/image/loading_displaying.js b/src/image/loading_displaying.js index f257b2a0d3..53150839ce 100644 --- a/src/image/loading_displaying.js +++ b/src/image/loading_displaying.js @@ -143,10 +143,10 @@ p5.prototype.loadImage = function(path, successCallback, failureCallback) { e => { if (typeof failureCallback === 'function') { failureCallback(e); - self._decrementPreload(); } else { console.error(e); } + self._decrementPreload(); } ); } else { @@ -170,10 +170,10 @@ p5.prototype.loadImage = function(path, successCallback, failureCallback) { p5._friendlyFileLoadError(0, img.src); if (typeof failureCallback === 'function') { failureCallback(e); - self._decrementPreload(); } else { console.error(e); } + self._decrementPreload(); }; // Set crossOrigin in case image is served with CORS headers. @@ -193,10 +193,10 @@ p5.prototype.loadImage = function(path, successCallback, failureCallback) { p5._friendlyFileLoadError(0, path); if (typeof failureCallback === 'function') { failureCallback(e); - self._decrementPreload(); } else { console.error(e); } + self._decrementPreload(); }); return pImg; }; diff --git a/src/io/files.js b/src/io/files.js index 88d627b25a..6ea1f9b5f7 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -298,8 +298,9 @@ p5.prototype.loadJSON = function(...args) { if (errorCallback) { errorCallback(err); } else { - throw err; + console.error(err); } + self._decrementPreload(); } ); @@ -494,8 +495,9 @@ p5.prototype.loadStrings = function(...args) { if (errorCallback) { errorCallback(err); } else { - throw err; + console.error(err); } + self._decrementPreload(); } ); @@ -757,6 +759,7 @@ p5.prototype.loadTable = function(path) { } else { console.error(err); } + self._decrementPreload(); } ); @@ -975,8 +978,9 @@ p5.prototype.loadXML = function(...args) { if (errorCallback) { errorCallback(err); } else { - throw err; + console.error(err); } + self._decrementPreload(); } ); @@ -1033,8 +1037,9 @@ p5.prototype.loadBytes = function(file, callback, errorCallback) { if (errorCallback) { errorCallback(err); } else { - throw err; + console.error(err); } + self._decrementPreload(); } ); return ret; diff --git a/src/typography/loading_displaying.js b/src/typography/loading_displaying.js index f625db3d99..32f29c9d15 100644 --- a/src/typography/loading_displaying.js +++ b/src/typography/loading_displaying.js @@ -135,9 +135,11 @@ p5.prototype.loadFont = function(path, onSuccess, onError) { if (err) { p5._friendlyFileLoadError(4, path); if (typeof onError !== 'undefined') { - return onError(err); + onError(err); + } else { + console.error(err, path); } - console.error(err, path); + self._decrementPreload(); return; } diff --git a/src/webgl/loading.js b/src/webgl/loading.js index 9e22824da4..5beb53bda0 100755 --- a/src/webgl/loading.js +++ b/src/webgl/loading.js @@ -498,6 +498,7 @@ p5.prototype.loadModel = function(path,options) { 'Sorry, the file type is invalid. Only OBJ and STL files are supported.' ); } + self._decrementPreload(); } return model; };