Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't continue loop for paused sketches #7334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't continue loop for paused sketches
If the sketch is paused when 'saveGif' is called don't resume looping
within 'saveGif'
MartinParrish committed Oct 25, 2024
commit af64639209feb800cc4f66d14b0df120c97c03f9
13 changes: 11 additions & 2 deletions src/image/loading_displaying.js
Original file line number Diff line number Diff line change
@@ -393,6 +393,9 @@ p5.prototype.saveGif = async function(
pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
}

// store current looping status
const wasLooping = this.isLooping();

// stop the loop since we are going to manually redraw
this.noLoop();

@@ -452,7 +455,10 @@ p5.prototype.saveGif = async function(
}
if (!silent) p.html('Frames processed, generating color palette...');

this.loop();
if (wasLooping) {
this.loop();
}

this.pixelDensity(lastPixelDensity);

// create the gif encoder and the colorspace format
@@ -552,7 +558,10 @@ p5.prototype.saveGif = async function(

frames = [];
this._recording = false;
this.loop();

if (wasLooping) {
this.loop();
}

if (!silent){
p.html('Done. Downloading your gif!🌸');
16 changes: 16 additions & 0 deletions test/unit/image/downloading.js
Original file line number Diff line number Diff line change
@@ -370,6 +370,22 @@ suite('p5.prototype.saveGif', function() {
});
});

test('should continue looping sketch after saveGif', function(done) {
myp5.saveGif('mySketch', 2).then(() => {
assert.equal(myp5.isLooping(), true, 'Should still be looping');
done();
});
});

test('should not continue looping paused sketch after saveGif',
function(done) {
myp5.noLoop();
myp5.saveGif('mySketch', 2).then(() => {
assert.equal(myp5.isLooping(), false, 'Should not be looping');
done();
});
});

testWithDownload('should download a GIF', async function(blobContainer) {
myp5.saveGif(myGif, 3, 2);
await waitForBlob(blobContainer);