Browse Source

Canvas2D: dispose SceneNode of a WorldSpaceCanvas when this is created automatically and when the Canvas is disposed.
https://trello.com/c/y4U62vn4

nockawa 8 years ago
parent
commit
6b546ee3c6
1 changed files with 17 additions and 1 deletions
  1. 17 1
      canvas2D/src/Engine/babylon.canvas2d.ts

+ 17 - 1
canvas2D/src/Engine/babylon.canvas2d.ts

@@ -871,7 +871,9 @@
             let index = Canvas2D._INSTANCES.indexOf(this);
             if (index > -1) {
                 Canvas2D._INSTANCES.splice(index, 1);
-            }  
+            }
+
+            return true;
         }
 
         /**
@@ -1768,6 +1770,7 @@
             //}
 
             let createWorldSpaceNode = !settings || (settings.customWorldSpaceNode == null);
+            this._customWorldSpaceNode = !createWorldSpaceNode;
             let id = settings ? settings.id || null : null;
 
             // Set the max size of texture allowed for the adaptive render of the world space canvas cached bitmap
@@ -1811,6 +1814,19 @@
                 }
             }, Prim2DBase.isVisibleProperty.flagId);
         }
+
+        public dispose(): boolean {
+            if (!super.dispose()) {
+                return false;
+            }
+
+            if (!this._customWorldSpaceNode && this._worldSpaceNode) {
+                this._worldSpaceNode.dispose();
+                this._worldSpaceNode = null;
+            }
+        }
+
+        private _customWorldSpaceNode: boolean;
     }
 
     @className("ScreenSpaceCanvas2D", "BABYLON")