commit 07037b8a67d518ce54117ecbab938de4499d22e2
Author: leszek <leszek@koltunski.pl>
Date:   Wed Feb 15 22:51:23 2017 +0000

    a few lame fixes for the issues uncovered by Olimpic but it is still wrong

diff --git a/src/main/java/org/distorted/library/DistortedNode.java b/src/main/java/org/distorted/library/DistortedNode.java
index 29488f1..32f4a67 100644
--- a/src/main/java/org/distorted/library/DistortedNode.java
+++ b/src/main/java/org/distorted/library/DistortedNode.java
@@ -108,7 +108,8 @@ public class DistortedNode implements DistortedAttacheable
     int i;
 
     for(i=0; i<depth; i++) tmp +="   ";
-    tmp += ("NodeID="+mData.ID+" (nodes pointing: "+mData.numPointingNodes+" surfaceID="+mSurface.getID()+")");
+    tmp += ("NodeID="+mData.ID+" nodes pointing: "+mData.numPointingNodes+" surfaceID="+
+            mSurface.getID()+" FBO="+(mData.mFBO==null ? "null":mData.mFBO.getID()));
 
     android.util.Log.e("NODE", tmp);
 
@@ -145,11 +146,15 @@ public class DistortedNode implements DistortedAttacheable
 
     if( newData==null )
       {
+      android.util.Log.d("NODE", "list "+newList+" not found!! node surfaceID="+mSurface.getID());
+
       newData = new NodeData(++mNextNodeID,newList);
       mMapNodeID.put(newList,newData);
       }
     else if( newData.ID != mData.ID )
       {
+      android.util.Log.d("NODE", "list "+newList+" found!! node surfaceID="+mSurface.getID());
+
       newData.numPointingNodes++;
       }
 
@@ -161,28 +166,35 @@ public class DistortedNode implements DistortedAttacheable
         {
         if( mData.mFBO!=null )
           {
-          android.util.Log.d("NODE", "copying over FBO of node surfaceID="+mSurface.getID());
-
-          newData.mFBO = mData.mFBO;
-          fboUsed = true;
+          if( mData.numPointingNodes>1 )
+            {
+            android.util.Log.d("NODE", "creating1 new FBO of node surfaceID="+mSurface.getID());
+            newData.mFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_TREE,mSurface.getWidth(),mSurface.getHeight());
+            }
+          else
+            {
+            android.util.Log.d("NODE", "copying over FBO of node surfaceID="+mSurface.getID());
+            newData.mFBO = mData.mFBO;
+            fboUsed = true;
+            }
           }
         else
           {
-          android.util.Log.d("NODE", "creating new FBO of node surfaceID="+mSurface.getID());
+          android.util.Log.d("NODE", "creating2 new FBO of node surfaceID="+mSurface.getID());
           newData.mFBO = new DistortedFramebuffer(true,DistortedSurface.TYPE_TREE,mSurface.getWidth(),mSurface.getHeight());
           }
         }
       if( mNumChildren[0]==0 && newData.mFBO!=null )
         {
         android.util.Log.d("NODE", "deleting FBO of newData node!!");
-
-
         newData.mFBO.markForDeletion();
         newData.mFBO = null;
         }
 
       if( --mData.numPointingNodes==0 )
         {
+        android.util.Log.d("NODE", "deleting1 map key "+mData.key);
+
         mMapNodeID.remove(mData.key);
 
         if( !fboUsed && mData.mFBO!=null )
@@ -448,7 +460,13 @@ public class DistortedNode implements DistortedAttacheable
 
       if( mNumChildren[0]==0 && mData.mFBO!=null )
         {
-        mData.mFBO.markForDeletion();
+        if( --mData.numPointingNodes==0 )
+          {
+          mData.mFBO.markForDeletion();
+          android.util.Log.d("NODE", "deleting2 map key "+mData.key);
+
+          mMapNodeID.remove(mData.key);
+          }
         mData.mFBO = null;
         }
       }
@@ -481,7 +499,13 @@ public class DistortedNode implements DistortedAttacheable
 
       if( mData.mFBO!=null )
         {
-        mData.mFBO.markForDeletion();
+        if( --mData.numPointingNodes==0 )
+          {
+          mData.mFBO.markForDeletion();
+          android.util.Log.d("NODE", "deleting3 map key "+mData.key);
+
+          mMapNodeID.remove(mData.key);
+          }
         mData.mFBO = null;
         }
       }
