Browse Source

dispose renderGroupObserver

KK 8 years ago
parent
commit
ee60f74b34
1 changed files with 11 additions and 1 deletions
  1. 11 1
      canvas2D/src/Engine/babylon.canvas2d.ts

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

@@ -101,6 +101,10 @@
             this._uid = null;
             this._uid = null;
             this._cachedCanvasGroup = null;
             this._cachedCanvasGroup = null;
 
 
+            this._renderingGroupObserver = null;
+            this._beforeRenderObserver = null;
+            this._afterRenderObserver = null;
+
             this._profileInfoText = null;
             this._profileInfoText = null;
 
 
             Prim2DBase._isCanvasInit = false;
             Prim2DBase._isCanvasInit = false;
@@ -188,7 +192,7 @@
                     if (!settings.renderingPhase.camera || settings.renderingPhase.renderingGroupID==null) {
                     if (!settings.renderingPhase.camera || settings.renderingPhase.renderingGroupID==null) {
                         throw Error("You have to specify a valid camera and renderingGroup");
                         throw Error("You have to specify a valid camera and renderingGroup");
                     }
                     }
-                    this._scene.onRenderingGroupObservable.add((e, s) => {
+                    this._renderingGroupObserver = this._scene.onRenderingGroupObservable.add((e, s) => {
                         if (this._scene.activeCamera === settings.renderingPhase.camera) {
                         if (this._scene.activeCamera === settings.renderingPhase.camera) {
                             this._engine.clear(null, false, true, true);
                             this._engine.clear(null, false, true, true);
                             this._render();
                             this._render();
@@ -843,6 +847,11 @@
                 this._setupInteraction(false);
                 this._setupInteraction(false);
             }
             }
 
 
+            if (this._renderingGroupObserver) {
+                this._scene.onRenderingGroupObservable.remove(this._renderingGroupObserver);
+                this._renderingGroupObserver = null;
+            }
+
             if (this._beforeRenderObserver) {
             if (this._beforeRenderObserver) {
                 this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
                 this._scene.onBeforeRenderObservable.remove(this._beforeRenderObserver);
                 this._beforeRenderObserver = null;
                 this._beforeRenderObserver = null;
@@ -1219,6 +1228,7 @@
         private _cachingStrategy: number;
         private _cachingStrategy: number;
         private _hierarchyLevelMaxSiblingCount: number;
         private _hierarchyLevelMaxSiblingCount: number;
         private _groupCacheMaps: StringDictionary<MapTexture[]>;
         private _groupCacheMaps: StringDictionary<MapTexture[]>;
+        private _renderingGroupObserver: Observer<RenderingGroupInfo>;
         private _beforeRenderObserver: Observer<Scene>;
         private _beforeRenderObserver: Observer<Scene>;
         private _afterRenderObserver: Observer<Scene>;
         private _afterRenderObserver: Observer<Scene>;
         private _supprtInstancedArray: boolean;
         private _supprtInstancedArray: boolean;