commit fb001affbae3194674654313d898175672b06374
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Jan 8 17:08:36 2021 +0100

    Plug two more memory leaks. It should be fine now.

diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
index 09dc9e2..714dc21 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
@@ -418,6 +418,13 @@ public abstract class EffectQueue implements InternalMaster.Slave
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void markForDeletion()
+    {
+    mUBP.markForDeletion();
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void doWork()
diff --git a/src/main/java/org/distorted/library/effectqueue/UniformBlockProperties.java b/src/main/java/org/distorted/library/effectqueue/UniformBlockProperties.java
index 492dbd7..4100818 100644
--- a/src/main/java/org/distorted/library/effectqueue/UniformBlockProperties.java
+++ b/src/main/java/org/distorted/library/effectqueue/UniformBlockProperties.java
@@ -94,6 +94,13 @@ class UniformBlockProperties
     mUBO.invalidate();
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void markForDeletion()
+    {
+    mUBO.markForDeletion();
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void print(int num)
diff --git a/src/main/java/org/distorted/library/main/DistortedEffects.java b/src/main/java/org/distorted/library/main/DistortedEffects.java
index ea3d838..8440d4f 100644
--- a/src/main/java/org/distorted/library/main/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/main/DistortedEffects.java
@@ -181,6 +181,18 @@ public class DistortedEffects
     return mQueues[num].add(effect,position);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
+ */
+  public void markForDeletion()
+    {
+    for( int i=0; i<EffectType.LENGTH; i++)
+      {
+      mQueues[i].markForDeletion();
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Return number of effects of the given type currently in the Queue.
diff --git a/src/main/java/org/distorted/library/main/InternalMaster.java b/src/main/java/org/distorted/library/main/InternalMaster.java
index dc2a61a..b174841 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.Set;
+import java.util.ArrayList;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -48,25 +48,53 @@ public class InternalMaster
 
   static boolean toDo()
     {
-    Set<Slave> set = InternalStackFrameList.getSet();
-    int numSlaves = set.size();
+    Slave slave;
+    ArrayList<Slave> list = InternalStackFrameList.getSet();
+    int numSlaves = list.size();
 
-    if( numSlaves>0 )
+    try
       {
-      for(Slave slave: set)
+      for(int i=0; i<numSlaves; i++)
         {
- 			  if( slave!=null ) slave.doWork();
- 		    }
- 		  return true;
+        slave = list.remove(0);
+        if( slave!=null ) slave.doWork();
+        }
+      }
+    catch(IndexOutOfBoundsException ie)
+      {
+      // onDestroy must have been called, ignore
       }
 
-    return false;
+    return numSlaves>0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static void newSlave(Slave s)
     {
-    InternalStackFrameList.getSet().add(s);
+    ArrayList<Slave> list = InternalStackFrameList.getSet();
+    int num = list.size();
+    boolean found = false;
+    Slave tmp;
+
+    try
+      {
+      for(int i=0; i<num; i++)
+        {
+        tmp = list.get(i);
+
+        if( tmp==s )
+          {
+          found = true;
+          break;
+          }
+        }
+      }
+    catch(IndexOutOfBoundsException ie)
+      {
+      // onDestroy must have been called, ignore
+      }
+
+    if( !found ) list.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 2d76abb..50fdb9b 100644
--- a/src/main/java/org/distorted/library/main/InternalStackFrame.java
+++ b/src/main/java/org/distorted/library/main/InternalStackFrame.java
@@ -23,9 +23,7 @@ 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;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -72,7 +70,7 @@ public class InternalStackFrame
   private long mNextNodeID;
 
   //////////////////////////////////////////////////////////////////
-  private Set<InternalMaster.Slave> mSlaves;                      // InternalMaster
+  private ArrayList<InternalMaster.Slave> mSlaves;                // InternalMaster
 
   ////////////////////////////////////////////////////////////////// EffectQueue
   private long mNextQueueID;                                      //
@@ -86,7 +84,7 @@ public class InternalStackFrame
     mDoneList     = new LinkedList<>();
     mToDoMap      = new HashMap<>();
     mMapNodeID    = new HashMap<>();
-    mSlaves       = new HashSet<>();
+    mSlaves       = new ArrayList<>();
     mMapID        = new HashMap<>();
     mNextEffectsID= 0;
     mNextClientID = 0;
@@ -339,7 +337,7 @@ public class InternalStackFrame
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  Set<InternalMaster.Slave> getSet()
+  ArrayList<InternalMaster.Slave> getSet()
     {
     return mSlaves;
     }
diff --git a/src/main/java/org/distorted/library/main/InternalStackFrameList.java b/src/main/java/org/distorted/library/main/InternalStackFrameList.java
index b6aa2df..f186684 100644
--- a/src/main/java/org/distorted/library/main/InternalStackFrameList.java
+++ b/src/main/java/org/distorted/library/main/InternalStackFrameList.java
@@ -254,7 +254,7 @@ public class InternalStackFrameList
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  static Set<InternalMaster.Slave> getSet()
+  static ArrayList<InternalMaster.Slave> getSet()
     {
     return mCurrentFrame.getSet();
     }
