commit 7c6d11c89f251bdd2da5c259afc039d2adcd02e8
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Apr 28 16:41:33 2017 +0100

    Do not change postprocessing Quality mid-render but go through the Master.

diff --git a/src/main/java/org/distorted/library/DistortedEffectsPostprocess.java b/src/main/java/org/distorted/library/DistortedEffectsPostprocess.java
index bfdb77b..b25ec53 100644
--- a/src/main/java/org/distorted/library/DistortedEffectsPostprocess.java
+++ b/src/main/java/org/distorted/library/DistortedEffectsPostprocess.java
@@ -22,6 +22,8 @@ package org.distorted.library;
 import org.distorted.library.message.EffectListener;
 import org.distorted.library.type.Data1D;
 
+import java.util.ArrayList;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -35,8 +37,10 @@ import org.distorted.library.type.Data1D;
  * <p>
  * The queue holds actual effects to be applied to a given bucket of several (DistortedTexture,MeshObject) combos.
  */
-public class DistortedEffectsPostprocess
+public class DistortedEffectsPostprocess implements DistortedSlave
   {
+  private static final int MIPMAP = 0;
+
   private static long mNextID =0;
   private long mID;
 
@@ -44,6 +48,20 @@ public class DistortedEffectsPostprocess
 
   private boolean postprocessCloned;
 
+  private class Job
+    {
+    int type;
+    int level;
+
+    Job(int t, int l)
+      {
+      type = t;
+      level= l;
+      }
+    }
+
+  private ArrayList<Job> mJobs = new ArrayList<>();
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void initializeEffectLists(DistortedEffectsPostprocess d, int flags)
@@ -125,6 +143,34 @@ public class DistortedEffectsPostprocess
     initializeEffectLists(dc,flags);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * This is not really part of the public API. Has to be public only because it is a part of the
+ * DistortedSlave interface, which should really be a class that we extend here instead but
+ * Java has no multiple inheritance.
+ *
+ * @y.exclude
+ */
+  public void doWork()
+    {
+    int num = mJobs.size();
+    Job job;
+
+    for(int i=0; i<num; i++)
+      {
+      job = mJobs.remove(0);
+
+      switch(job.type)
+        {
+        case MIPMAP: int level = job.level;
+                     mP.mQualityLevel = level;
+                     mP.mQualityScale = 1.0f;
+                     for(int j=0; j<level; j++) mP.mQualityScale*=EffectQuality.MULTIPLIER;
+                     break;
+        }
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Releases all resources. After this call, the queue should not be used anymore.
@@ -291,15 +337,14 @@ public class DistortedEffectsPostprocess
  * <p>
  * This works by rendering into smaller and smaller intermediate buffers. Each step renders into a
  * buffer that's half the size of the previous one.
+ * <p>
+ * We cannot this during mid-render - thus, give it to the Master to assign us back this job on the
+ * next render.
  */
   public void setQuality(EffectQuality quality)
     {
-    int level = quality.level;
-
-    mP.mQualityLevel = level;
-    mP.mQualityScale = 1.0f;
-
-    for(int i=0; i<level; i++) mP.mQualityScale*=EffectQuality.MULTIPLIER;
+    mJobs.add(new Job(MIPMAP,quality.level));
+    DistortedMaster.newSlave(this);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////   
diff --git a/src/main/java/org/distorted/library/DistortedInputSurface.java b/src/main/java/org/distorted/library/DistortedInputSurface.java
index b5f833b..5f5004f 100644
--- a/src/main/java/org/distorted/library/DistortedInputSurface.java
+++ b/src/main/java/org/distorted/library/DistortedInputSurface.java
@@ -21,7 +21,7 @@ package org.distorted.library;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * A Surface that we can set as Input, i.e. take its rectangle of pixels and skin our Mesh with it.
+ * A Surface that we can set as an Input (take its rectangle of pixels and skin a Mesh with it).
  */
 
 public interface DistortedInputSurface
