File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -2145,6 +2145,16 @@ public void handleDraw() {
21452145
21462146 g .beginDraw ();
21472147
2148+ if (requestedNoLoop ) {
2149+ // noLoop() was called in the previous frame, with a GL renderer, but now
2150+ // we are sure that the frame is properly displayed.
2151+ looping = false ;
2152+ requestedNoLoop = false ;
2153+ // We are done, we only need to finish the frame and exit.
2154+ g .endDraw ();
2155+ return ;
2156+ }
2157+
21482158 long now = System .nanoTime ();
21492159
21502160 if (frameCount == 0 ) {
@@ -2246,9 +2256,21 @@ synchronized public void loop() {
22462256 }
22472257
22482258
2259+ // This auxiliary variable is used to implement a little hack that fixes
2260+ // https://github.com/processing/processing-android/issues/147
2261+ // on older devices where the last frame cannot be maintained after ending
2262+ // the rendering in GL. The trick consists in running one more frame after the
2263+ // noLoop() call, which ensures that the FBO layer is properly initialized
2264+ // and drawn with the contents of the previous frame.
2265+ private boolean requestedNoLoop = false ;
2266+
22492267 synchronized public void noLoop () {
22502268 if (looping ) {
2251- looping = false ;
2269+ if (g instanceof PGraphicsOpenGL ) {
2270+ requestedNoLoop = true ;
2271+ } else {
2272+ looping = false ;
2273+ }
22522274 }
22532275 }
22542276
Original file line number Diff line number Diff line change @@ -942,6 +942,8 @@ protected void saveFirstFrame() {
942942
943943
944944 protected void restoreFirstFrame () {
945+ if (firstFrame == null ) return ;
946+
945947 IntBuffer tex = allocateIntBuffer (1 );
946948 genTextures (1 , tex );
947949
You can’t perform that action at this time.
0 commit comments