Skip to content

Commit 095f220

Browse files
authored
Merge pull request #8132 from ayushman1210/fix/black-frame_dev-2.0
fixed the bug of black-frames
2 parents 6c6ac6c + 7dbc74a commit 095f220

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/image/loading_displaying.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ function loadingDisplaying(p5, fn){
256256
units: 'seconds',
257257
silent: false,
258258
notificationDuration: 0,
259-
notificationID: 'progressBar'
259+
notificationID: 'progressBar',
260+
reset: true
260261
}
261262
) {
262263
// validate parameters
@@ -273,7 +274,7 @@ function loadingDisplaying(p5, fn){
273274
const silent = (options && options.silent) || false;
274275
const notificationDuration = (options && options.notificationDuration) || 0;
275276
const notificationID = (options && options.notificationID) || 'progressBar';
276-
277+
const resetAnimation = (options && options.reset !== undefined) ? options.reset : true;
277278
// if arguments in the options object are not correct, cancel operation
278279
if (typeof delay !== 'number') {
279280
throw TypeError('Delay parameter must be a number');
@@ -324,11 +325,19 @@ function loadingDisplaying(p5, fn){
324325
// that duration translates to
325326
const nFrames = units === 'seconds' ? duration * _frameRate : duration;
326327
const nFramesDelay = units === 'seconds' ? delay * _frameRate : delay;
327-
const totalNumberOfFrames = nFrames + nFramesDelay;
328328

329329
// initialize variables for the frames processing
330-
let frameIterator = nFramesDelay;
331-
this.frameCount = frameIterator;
330+
let frameIterator;
331+
let totalNumberOfFrames;
332+
333+
if (resetAnimation) {
334+
frameIterator = nFramesDelay;
335+
this.frameCount = frameIterator;
336+
totalNumberOfFrames = nFrames + nFramesDelay;
337+
} else {
338+
frameIterator = this.frameCount + nFramesDelay;
339+
totalNumberOfFrames = frameIterator + nFrames;
340+
}
332341

333342
const lastPixelDensity = this._renderer._pixelDensity;
334343
this.pixelDensity(1);
@@ -371,7 +380,7 @@ function loadingDisplaying(p5, fn){
371380
//
372381
// Waiting on this empty promise means we'll continue as soon as setup
373382
// finishes without waiting for another frame.
374-
await Promise.resolve();
383+
await new Promise(requestAnimationFrame)
375384

376385
while (frameIterator < totalNumberOfFrames) {
377386
/*
@@ -381,7 +390,7 @@ function loadingDisplaying(p5, fn){
381390
to be drawn and immediately save it to a buffer and continue
382391
*/
383392
this.redraw();
384-
393+
await new Promise(requestAnimationFrame);
385394
// depending on the context we'll extract the pixels one way
386395
// or another
387396
let data = undefined;

0 commit comments

Comments
 (0)