commit 8d98b65fbfccad698eed507b5a0ced17f423e34e
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun Oct 3 00:40:46 2021 +0200

    Move destroying most of statics from onDestroy() earlier, to onPause().
    
    Reason: doing this in onDestroy() is too late, because when we have two activities, and switch between them, first the ending's Activity onPause() is called, then the starting Activity's onResume, then it's onSurfaceCreated(), then we insert all the effects, and only then the ending Activity onDestroy() gets fired off - and this might destroy the already enabled effects, like for example the Programs of the Postprocessing effects.

diff --git a/src/main/java/org/distorted/library/effect/Effect.java b/src/main/java/org/distorted/library/effect/Effect.java
index c7a94f4..d01b1ca 100644
--- a/src/main/java/org/distorted/library/effect/Effect.java
+++ b/src/main/java/org/distorted/library/effect/Effect.java
@@ -93,7 +93,7 @@ public abstract class Effect
  *
  * @y.exclude
  */
-  public static void onDestroy()
+  public static void onPause()
     {
     for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
 
diff --git a/src/main/java/org/distorted/library/main/DistortedLibrary.java b/src/main/java/org/distorted/library/main/DistortedLibrary.java
index 74d9d0b..abc7646 100644
--- a/src/main/java/org/distorted/library/main/DistortedLibrary.java
+++ b/src/main/java/org/distorted/library/main/DistortedLibrary.java
@@ -1121,7 +1121,14 @@ public class DistortedLibrary
   public static void onPause(long id)
     {
     InternalStackFrameList.onPause(id);
+
     Dynamic.onPause();  // common for all frames
+    InternalOutputSurface.onPause();
+    Effect.onPause();
+    DeferredJobs.onPause();
+
+    mOITCompilationAttempted = false;
+    mNeedsTransformFeedback  = false;
 
     mLinkedListSSBO[0]= -1;
     mAtomicCounter = null;
@@ -1161,13 +1168,6 @@ public class DistortedLibrary
     if( InternalStackFrameList.isInitialized() )
       {
       InternalStackFrameList.onDestroy(id);
-
-      InternalOutputSurface.onDestroy(); // those three really destroy
-      Effect.onDestroy();                // static data that does not
-      DeferredJobs.onDestroy();          // need to be part of a frame
-
-      mOITCompilationAttempted = false;
-      mNeedsTransformFeedback  = false;
       }
     }
 
diff --git a/src/main/java/org/distorted/library/main/InternalOutputSurface.java b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
index 3e59aee..e6cd73e 100644
--- a/src/main/java/org/distorted/library/main/InternalOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
@@ -207,7 +207,7 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  static synchronized void onDestroy()
+  static synchronized void onPause()
     {
     for (int j=0; j<EffectQuality.LENGTH; j++)
       if( mBuffer[j]!=null )
diff --git a/src/main/java/org/distorted/library/mesh/DeferredJobs.java b/src/main/java/org/distorted/library/mesh/DeferredJobs.java
index fe4d6c2..fc37d2e 100644
--- a/src/main/java/org/distorted/library/mesh/DeferredJobs.java
+++ b/src/main/java/org/distorted/library/mesh/DeferredJobs.java
@@ -401,7 +401,7 @@ public class DeferredJobs
  *
  * @y.exclude
  */
-  public static void onDestroy()
+  public static void onPause()
     {
     int num = mJobs.size();
 
