浏览代码

fix for NME preview pop out bug

Kyle Belfort 5 年之前
父节点
当前提交
02a2cb712c

+ 1 - 0
dist/preview release/what's new.md

@@ -301,6 +301,7 @@
 - Disposing of the depthReducer used in CSM ([Popov72](https://github.com/Popov72))
 - Fixed an issue with teleportation detach and attach ([#7419](https://github.com/BabylonJS/Babylon.js/issues/7419)) ([RaananW](https://github.com/RaananW/))
 - Physics compound calculations were incorrect ([#7407](https://github.com/BabylonJS/Babylon.js/issues/7407)) ([RaananW](https://github.com/RaananW/))
+- Fix bug NME bug where preview area crashes on pop up when NME is opened from playground ([Kyle Belfort](https://github.com/belfortk))
 
 ## Breaking changes
 

+ 1 - 0
nodeEditor/src/globalState.ts

@@ -16,6 +16,7 @@ export class GlobalState {
     nodeMaterial: NodeMaterial;
     hostElement: HTMLElement;
     hostDocument: HTMLDocument;
+    hostWindow: Window;
     onSelectionChangedObservable = new Observable<Nullable<GraphNode | NodeLink | GraphFrame>>();
     onRebuildRequiredObservable = new Observable<void>();
     onResetRequiredObservable = new Observable<void>();

+ 5 - 5
nodeEditor/src/graphEditor.tsx

@@ -544,7 +544,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, State> {
             showPreviewPopUp : true
         });
         this.createPopUp();
-        window.addEventListener('beforeunload', this.handleClosingPopUp);
+        this.props.globalState.hostWindow.addEventListener('beforeunload', this.handleClosingPopUp);
     }
 
     handleClosingPopUp = () => {
@@ -593,8 +593,8 @@ export class GraphEditor extends React.Component<IGraphEditorProps, State> {
         const windowCreationOptionsList = {
             width: width,
             height: height,
-            top: (window.innerHeight - width) / 2 + window.screenY,
-            left: (window.innerWidth - height) / 2 + window.screenX
+            top: (this.props.globalState.hostWindow.innerHeight - width) / 2 + window.screenY,
+            left: (this.props.globalState.hostWindow.innerWidth - height) / 2 + window.screenX
         };
 
         var windowCreationOptions = Object.keys(windowCreationOptionsList)
@@ -603,7 +603,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, State> {
             )
             .join(',');
 
-        const popupWindow = window.open("", title, windowCreationOptions);
+        const popupWindow = this.props.globalState.hostWindow.open("", title, windowCreationOptions);
         if (!popupWindow) {
             return null;
         }
@@ -628,7 +628,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, State> {
 
         popupWindow.document.body.appendChild(parentControl);
 
-        this.copyStyles(window.document, parentDocument);
+        this.copyStyles(this.props.globalState.hostWindow.document, parentDocument);
 
         (this as any)[windowVariableName] = popupWindow;
 

+ 2 - 1
nodeEditor/src/nodeEditor.ts

@@ -41,10 +41,11 @@ export class NodeEditor {
         }
         
         let globalState = new GlobalState();
-        globalState.nodeMaterial = options.nodeMaterial
+        globalState.nodeMaterial = options.nodeMaterial;
         globalState.hostElement = hostElement;
         globalState.hostDocument = hostElement.ownerDocument!;
         globalState.customSave = options.customSave;
+        globalState.hostWindow =  hostElement.ownerDocument!.defaultView!;
 
         const graphEditor = React.createElement(GraphEditor, {
             globalState: globalState