commit bd4b36be79a8311eb4839ce438b2adc33d50a57e
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Mar 20 22:47:43 2019 +0000

    Avoid a potential crash on exit

diff --git a/src/main/java/org/distorted/library/main/DistortedMaster.java b/src/main/java/org/distorted/library/main/DistortedMaster.java
index aaa0c96..32e112e 100644
--- a/src/main/java/org/distorted/library/main/DistortedMaster.java
+++ b/src/main/java/org/distorted/library/main/DistortedMaster.java
@@ -53,10 +53,17 @@ public class DistortedMaster
     Slave slave;
     int num = mSlaves.size();
 
-    for(int i=0; i<num; i++)
+    try
       {
-      slave = mSlaves.remove(0);
-      slave.doWork();
+      for(int i=0; i<num; i++)
+        {
+        slave = mSlaves.remove(0);
+        slave.doWork();
+        }
+      }
+    catch(IndexOutOfBoundsException ie)
+      {
+      // onDestroy must have been called, ignore
       }
 
     return ( num>0 );
@@ -70,16 +77,23 @@ public class DistortedMaster
     boolean found = false;
     Slave tmp;
 
-    for(int i=0; i<num; i++)
+    try
       {
-      tmp = mSlaves.get(i);
-
-      if( tmp==s )
+      for(int i=0; i<num; i++)
         {
-        found = true;
-        break;
+        tmp = mSlaves.get(i);
+
+        if( tmp==s )
+          {
+          found = true;
+          break;
+          }
         }
       }
+    catch(IndexOutOfBoundsException ie)
+      {
+      // onDestroy must have been called, ignore
+      }
 
     if( !found ) mSlaves.add(s);
     }
