commit ccd98f1c79eaf5e5f9a748a789ef8ef7da67c216
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Apr 26 17:54:25 2019 +0100

    Correct a bug in DistortedBuffer: we only mark it for creation when we actually have all the data ready, otherwise it can happen that create(0 is called before setData() !

diff --git a/src/main/java/org/distorted/library/main/DistortedBuffer.java b/src/main/java/org/distorted/library/main/DistortedBuffer.java
index f7a0687..b1e7896 100644
--- a/src/main/java/org/distorted/library/main/DistortedBuffer.java
+++ b/src/main/java/org/distorted/library/main/DistortedBuffer.java
@@ -42,21 +42,27 @@ public class DistortedBuffer extends DistortedObject
 
   public DistortedBuffer(int target, int usage)
     {
-    super(DistortedObject.NOT_CREATED_YET,DistortedObject.TYPE_USER);
+    super(DistortedObject.TYPE_USER);
 
     mIndex  = new int[1];
     mTarget = target;
     mUsage  = usage;
+    mBuffer = null;
+    mSize   = 0;
 
     recreate();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// mark for creation only now, when we do have all data ready, in order to avoid the situation
+// when create() would be called before this.
 
   public void setData(int size, Buffer buffer)
     {
     mSize   = size;
     mBuffer = buffer;
+
+    markForCreation();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/main/DistortedObject.java b/src/main/java/org/distorted/library/main/DistortedObject.java
index 296741b..57ceaba 100644
--- a/src/main/java/org/distorted/library/main/DistortedObject.java
+++ b/src/main/java/org/distorted/library/main/DistortedObject.java
@@ -210,19 +210,10 @@ abstract class DistortedObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  DistortedObject(int create, int type)
+  DistortedObject(int type)
     {
     mID  = type==TYPE_SYST ? --mNextSystemID : ++mNextClientID;
     mType= type;
-
-    if( create!=DONT_CREATE )
-      {
-      synchronized(mToDoLock)
-        {
-        mToDoMap.put(mID, new Job(this,JOB_CREATE) );
-        mToDo = true;
-        }
-      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/main/DistortedSurface.java b/src/main/java/org/distorted/library/main/DistortedSurface.java
index d93338f..797ccdf 100644
--- a/src/main/java/org/distorted/library/main/DistortedSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedSurface.java
@@ -41,7 +41,9 @@ public abstract class DistortedSurface extends DistortedObject
 
   DistortedSurface(int width, int height, int create, int numfbos, int numcolors, int type)
     {
-    super(create,type);
+    super(type);
+
+    if( create!=DONT_CREATE ) markForCreation();
 
     mNumFBOs      = numfbos;
     mNumColors    = numcolors;
