commit 3bbe4d67166c261cff34c33f93a84f2c9446ac6b
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun Nov 29 22:55:58 2020 +0100

    Put new things to the StackFrame.

diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
index 5a83492..5e778e4 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
@@ -53,9 +53,6 @@ public abstract class EffectQueue implements InternalMaster.Slave
   float[] mFloatUniforms;
   int[] mIntUniforms;
 
-  private static long mNextID = 1;
-  private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a
-                                                                         // single long - the queue ID.
   private long mID;
   private int mIndex;
   private boolean mCreated;
@@ -203,9 +200,10 @@ public abstract class EffectQueue implements InternalMaster.Slave
     {
     if( mNumEffects>0 )
       {
+      HashMap<ArrayList<Long>,Long> map = InternalStackFrameList.getMap();
       ArrayList<Long> list = new ArrayList<>();
-      for (int i = 0; i < mNumEffects; i++) list.add(mEffects[i].getID());
-      Long id = mMapID.get(list);
+      for (int i=0; i<mNumEffects; i++) list.add(mEffects[i].getID());
+      Long id = map.get(list);
 
       if( id!=null )
         {
@@ -213,8 +211,8 @@ public abstract class EffectQueue implements InternalMaster.Slave
         }
       else
         {
-        mMapID.put(list,mNextID);
-        mID = mNextID++;
+        mID = InternalStackFrameList.getNextQueueID();
+        map.put(list,mID);
         }
       }
     else
@@ -244,14 +242,6 @@ public abstract class EffectQueue implements InternalMaster.Slave
     return InternalStackFrameList.getMax(index);
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static void onDestroy()
-    {
-    mNextID = 1;
-    mMapID.clear();
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // this assumes 0<=effect
 
diff --git a/src/main/java/org/distorted/library/main/DistortedLibrary.java b/src/main/java/org/distorted/library/main/DistortedLibrary.java
index 7e1efe6..97d9a6f 100644
--- a/src/main/java/org/distorted/library/main/DistortedLibrary.java
+++ b/src/main/java/org/distorted/library/main/DistortedLibrary.java
@@ -1133,11 +1133,10 @@ public class DistortedLibrary
     if( InternalStackFrameList.isInitialized() )
       {
       InternalStackFrameList.onDestroy(id);
-      InternalMaster.onDestroy();
-      InternalOutputSurface.onDestroy();
-      EffectQueue.onDestroy();
-      Effect.onDestroy();
-      DeferredJobs.onDestroy();
+
+      InternalOutputSurface.onDestroy(); // those three really destroy
+      Effect.onDestroy();                // static data that does not
+      DeferredJobs.onDestroy();          // need to be part of a frame
 
       mOITCompilationAttempted = false;
       }
diff --git a/src/main/java/org/distorted/library/main/InternalMaster.java b/src/main/java/org/distorted/library/main/InternalMaster.java
index bdcd4b0..dc2a61a 100644
--- a/src/main/java/org/distorted/library/main/InternalMaster.java
+++ b/src/main/java/org/distorted/library/main/InternalMaster.java
@@ -19,7 +19,7 @@
 
 package org.distorted.library.main;
 
-import java.util.ArrayList;
+import java.util.Set;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -32,8 +32,6 @@ import java.util.ArrayList;
  */
 public class InternalMaster
   {
-  private static ArrayList<Slave> mSlaves = new ArrayList<>();
-
   public interface Slave
     {
     void doWork();
@@ -50,59 +48,25 @@ public class InternalMaster
 
   static boolean toDo()
     {
-    Slave slave;
-    int num = mSlaves.size();
+    Set<Slave> set = InternalStackFrameList.getSet();
+    int numSlaves = set.size();
 
-    try
+    if( numSlaves>0 )
       {
-      for(int i=0; i<num; i++)
+      for(Slave slave: set)
         {
-        slave = mSlaves.remove(0);
-
-        if( slave!=null ) slave.doWork();
-        }
-      }
-    catch(IndexOutOfBoundsException ie)
-      {
-      // onDestroy must have been called, ignore
+ 			  if( slave!=null ) slave.doWork();
+ 		    }
+ 		  return true;
       }
 
-    return ( num>0 );
+    return false;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static void newSlave(Slave s)
     {
-    int num = mSlaves.size();
-    boolean found = false;
-    Slave tmp;
-
-    try
-      {
-      for(int i=0; i<num; i++)
-        {
-        tmp = mSlaves.get(i);
-
-        if( tmp==s )
-          {
-          found = true;
-          break;
-          }
-        }
-      }
-    catch(IndexOutOfBoundsException ie)
-      {
-      // onDestroy must have been called, ignore
-      }
-
-    if( !found ) mSlaves.add(s);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  static void onDestroy()
-    {
-    mSlaves.clear();
+    InternalStackFrameList.getSet().add(s);
     }
   }
diff --git a/src/main/java/org/distorted/library/main/InternalStackFrame.java b/src/main/java/org/distorted/library/main/InternalStackFrame.java
index 7be306c..2d76abb 100644
--- a/src/main/java/org/distorted/library/main/InternalStackFrame.java
+++ b/src/main/java/org/distorted/library/main/InternalStackFrame.java
@@ -23,7 +23,9 @@ import org.distorted.library.effect.EffectType;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
+import java.util.Set;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -69,6 +71,14 @@ public class InternalStackFrame
   private HashMap<ArrayList<Long>, InternalNodeData> mMapNodeID;  // InternalNodeData
   private long mNextNodeID;
 
+  //////////////////////////////////////////////////////////////////
+  private Set<InternalMaster.Slave> mSlaves;                      // InternalMaster
+
+  ////////////////////////////////////////////////////////////////// EffectQueue
+  private long mNextQueueID;                                      //
+  private HashMap<ArrayList<Long>,Long> mMapID;                   // maps lists of Effect IDs (longs)
+                                                                  // to a single long - the queue ID.
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   InternalStackFrame(long taskID)
@@ -76,10 +86,13 @@ public class InternalStackFrame
     mDoneList     = new LinkedList<>();
     mToDoMap      = new HashMap<>();
     mMapNodeID    = new HashMap<>();
+    mSlaves       = new HashSet<>();
+    mMapID        = new HashMap<>();
     mNextEffectsID= 0;
     mNextClientID = 0;
     mNextSystemID = 0;
     mNextNodeID   = 0;
+    mNextQueueID  = 1;
     mTaskId       = taskID;
     mMax          = new int[EffectType.LENGTH];
 
@@ -285,6 +298,22 @@ public class InternalStackFrame
     return false;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public HashMap<ArrayList<Long>,Long> getMap()
+    {
+    return mMapID;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public long getNextQueueID()
+    {
+    mNextQueueID++;
+
+    return mNextQueueID-1;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   InternalNodeData getMapID(ArrayList<Long> key)
@@ -308,6 +337,13 @@ public class InternalStackFrame
     mMapNodeID.remove(key);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  Set<InternalMaster.Slave> getSet()
+    {
+    return mSlaves;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void debugLists(String frameMarker)
diff --git a/src/main/java/org/distorted/library/main/InternalStackFrameList.java b/src/main/java/org/distorted/library/main/InternalStackFrameList.java
index c3bbe15..b6aa2df 100644
--- a/src/main/java/org/distorted/library/main/InternalStackFrameList.java
+++ b/src/main/java/org/distorted/library/main/InternalStackFrameList.java
@@ -22,6 +22,8 @@ package org.distorted.library.main;
 import org.distorted.library.message.EffectMessageSender;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Set;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -250,6 +252,13 @@ public class InternalStackFrameList
     mCurrentFrame.removeKeyFromMap(key);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static Set<InternalMaster.Slave> getSet()
+    {
+    return mCurrentFrame.getSet();
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -279,4 +288,21 @@ public class InternalStackFrameList
     {
     return mCurrentFrame.setMax(index,max);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static HashMap<ArrayList<Long>,Long> getMap()
+    {
+    return mCurrentFrame.getMap();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static long getNextQueueID()
+    {
+    return mCurrentFrame.getNextQueueID();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
 }
