From 9d7cde21d3c36c64ff75739f6726e8d45de6f140 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 21 Mar 2023 18:37:25 -0400 Subject: [PATCH] Fix black first frame when rendering gifs in setup --- src/image/loading_displaying.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/image/loading_displaying.js b/src/image/loading_displaying.js index 78c4b205ea..c3aa1cd205 100644 --- a/src/image/loading_displaying.js +++ b/src/image/loading_displaying.js @@ -317,6 +317,14 @@ p5.prototype.saveGif = async function( // stop the loop since we are going to manually redraw this.noLoop(); + // Defer execution until the rest of the call stack finishes, allowing the + // rest of `setup` to be called (and, importantly, canvases hidden in setup + // to be unhidden.) + // + // Waiting on this empty promise means we'll continue as soon as setup + // finishes without waiting for another frame. + await Promise.resolve(); + while (frameIterator < totalNumberOfFrames) { /* we draw the next frame. this is important, since