Skip to content

Commit 23d5d90

Browse files
committed
set looping to false before beginDraw/endDraw
1 parent 3852151 commit 23d5d90

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

core/src/processing/core/PApplet.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ public class PApplet extends Object implements ActivityAPI, PConstants {
308308

309309
protected boolean looping;
310310

311+
// This auxiliary variable is used to implement a little hack that fixes
312+
// https://github.com/processing/processing-android/issues/147
313+
// on older devices where the last frame cannot be maintained after ending
314+
// the rendering in GL. The trick consists in running one more frame after the
315+
// noLoop() call, which ensures that the FBO layer is properly initialized
316+
// and drawn with the contents of the previous frame.
317+
protected boolean requestedNoLoop = false;
318+
311319
/** flag set to true when a redraw is asked for by the user */
312320
protected boolean redraw;
313321

@@ -1779,22 +1787,27 @@ public void handleDraw() {
17791787
}
17801788

17811789
insideDraw = true;
1782-
g.beginDraw();
1790+
17831791
// if (recorder != null) {
17841792
// recorder.beginDraw();
17851793
// }
17861794

17871795
if (requestedNoLoop) {
1788-
// noLoop() was called in the previous frame, with a GL renderer, but now
1796+
// noLoop() was called sometime in the previous frame with a GL renderer, but only now
17891797
// we are sure that the frame is properly displayed.
17901798
looping = false;
1791-
requestedNoLoop = false;
1792-
// We are done, we only need to finish the frame and exit.
1799+
// Perform a full frame draw, to ensure that the previous frame is properly displayed (see
1800+
// comment in the declaration of requestedNoLoop).
1801+
g.beginDraw();
17931802
g.endDraw();
1803+
requestedNoLoop = false;
17941804
insideDraw = false;
17951805
return;
17961806
}
17971807

1808+
g.beginDraw();
1809+
1810+
17981811
long now = System.nanoTime();
17991812

18001813
if (frameCount == 0) {
@@ -1878,14 +1891,6 @@ synchronized public void loop() {
18781891
}
18791892

18801893

1881-
// This auxiliary variable is used to implement a little hack that fixes
1882-
// https://github.com/processing/processing-android/issues/147
1883-
// on older devices where the last frame cannot be maintained after ending
1884-
// the rendering in GL. The trick consists in running one more frame after the
1885-
// noLoop() call, which ensures that the FBO layer is properly initialized
1886-
// and drawn with the contents of the previous frame.
1887-
private boolean requestedNoLoop = false;
1888-
18891894
synchronized public void noLoop() {
18901895
if (looping) {
18911896
if (g instanceof PGraphicsOpenGL) {

core/src/processing/core/PSurfaceNone.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ public boolean stopThread() {
434434
if (thread == null) {
435435
return false;
436436
}
437+
437438
thread.interrupt();
439+
thread = null;
440+
438441
return true;
439442
}
440443

@@ -452,9 +455,8 @@ public void setFrameRate(float fps) {
452455

453456

454457
protected void checkPause() throws InterruptedException {
455-
// if (paused) {
456-
synchronized (pauseObject) {
457-
while (paused) {
458+
synchronized (pauseObject) {
459+
while (paused) {
458460
pauseObject.wait();
459461
}
460462
}

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5709,6 +5709,7 @@ protected void drawPixels(int[] pixBuffer, int x, int y, int w, int h) {
57095709

57105710
@Override
57115711
protected void saveState() {
5712+
/*
57125713
// Queue the pixel read operation so it is performed when the surface is ready
57135714
pgl.queueEvent(new Runnable() {
57145715
@Override
@@ -5727,21 +5728,31 @@ public void run() {
57275728
} catch (ArrayIndexOutOfBoundsException e) {}
57285729
}
57295730
});
5731+
*/
57305732
}
57315733

57325734

57335735
@Override
57345736
protected void restoreState() {
57355737
}
57365738

5739+
57375740
@Override
57385741
protected void restoreSurface() {
5742+
/*
57395743
if (changed) {
57405744
changed = false;
57415745
if (restorePixels != null) {
57425746
// Set restore count to 2 so it draws the bitmap two frames after surface change, otherwise
57435747
// the restoration does not work because the OpenGL renderer sometimes resizes the surface
5744-
// twice after restoring the app to the foreground (?)
5748+
// twice after restoring the app to the foreground... this may be due to broken graphics
5749+
// drivers, hacks in the GLSurfaceView class from the Replica Island game point to that,
5750+
// although those seem to be quite old:
5751+
// https://gamedev.stackexchange.com/questions/12629/workaround-to-losing-the-opengl-context-when-android-pauses
5752+
// "It fails in a very specific case: when the EGL context is lost due to resource constraints,
5753+
// and then recreated, if GL commands are sent within two frames of the surface being created
5754+
// then eglSwapBuffers() will hang."
5755+
// However, the same number showing up makes me thing this issue continue to exist to this day.
57455756
restoreCount = 2;
57465757
}
57475758
} else if (restoreCount > 0) {
@@ -5752,6 +5763,7 @@ protected void restoreSurface() {
57525763
restorePixels = null;
57535764
}
57545765
}
5766+
*/
57555767
}
57565768

57575769
//////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)