Browse Source

Dispose of the graph editor resources when closing the popup

Popov72 4 năm trước cách đây
mục cha
commit
17de216074

+ 1 - 0
nodeEditor/src/globalState.ts

@@ -42,6 +42,7 @@ export class GlobalState {
     onCandidatePortSelectedObservable = new Observable<Nullable<NodePort | FrameNodePort>>();
     onImportFrameObservable = new Observable<any>();
     onGraphNodeRemovalObservable = new Observable<GraphNode>();
+    onPopupClosedObservable = new Observable<void>();
     onGetNodeFromBlock: (block: NodeMaterialBlock) => GraphNode;
     onGridSizeChanged = new Observable<void>();
     onExposePortOnFrameObservable = new Observable<GraphNode>();

+ 6 - 0
nodeEditor/src/graphEditor.tsx

@@ -120,12 +120,17 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
         if (this.props.globalState.hostDocument) {
             this._graphCanvas = (this.refs["graphCanvas"] as GraphCanvasComponent);
             this._previewManager = new PreviewManager(this.props.globalState.hostDocument.getElementById("preview-canvas") as HTMLCanvasElement, this.props.globalState);
+            (this.props.globalState as any)._previewManager = this._previewManager;
         }
 
         if (navigator.userAgent.indexOf("Mobile") !== -1) {
             ((this.props.globalState.hostDocument || document).querySelector(".blocker") as HTMLElement).style.visibility = "visible";
         }
 
+        this.props.globalState.onPopupClosedObservable.addOnce(() => {
+            this.componentWillUnmount();
+        });
+
         this.build();
     }
 
@@ -136,6 +141,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
 
         if (this._previewManager) {
             this._previewManager.dispose();
+            this._previewManager = null as any;
         }
     }
 

+ 4 - 0
nodeEditor/src/nodeEditor.ts

@@ -68,6 +68,10 @@ export class NodeEditor {
 
         this._CurrentState = globalState;
 
+        globalState.hostWindow.addEventListener('beforeunload', () => {
+            globalState.onPopupClosedObservable.notifyObservers();
+        });
+
         // Close the popup window when the page is refreshed or scene is disposed
         var popupWindow = (Popup as any)["node-editor"];
         if (globalState.nodeMaterial && popupWindow) {