Browse Source

Fixing possible error with screenshot

There is a possibility, that when a user has two cameras and delivers
the wrong size variable, the active camera will be replaced and never
set back.
Raanan Weber 10 năm trước cách đây
mục cha
commit
fd3daaf551
2 tập tin đã thay đổi với 14 bổ sung14 xóa
  1. 6 6
      src/Tools/babylon.tools.js
  2. 8 8
      src/Tools/babylon.tools.ts

+ 6 - 6
src/Tools/babylon.tools.js

@@ -444,12 +444,6 @@ var BABYLON;
         Tools.CreateScreenshot = function (engine, camera, size, successCallback) {
             var width;
             var height;
-            var scene = camera.getScene();
-            var previousCamera = null;
-            if (scene.activeCamera !== camera) {
-                previousCamera = scene.activeCamera;
-                scene.activeCamera = camera;
-            }
             //If a precision value is specified
             if (size.precision) {
                 width = Math.round(engine.getRenderWidth() * size.precision);
@@ -478,6 +472,12 @@ var BABYLON;
                 Tools.Error("Invalid 'size' parameter !");
                 return;
             }
+            var scene = camera.getScene();
+            var previousCamera = null;
+            if (scene.activeCamera !== camera) {
+                previousCamera = scene.activeCamera;
+                scene.activeCamera = camera;
+            }
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
             var texture = new BABYLON.RenderTargetTexture("screenShot", size, scene, false, false);
             texture.renderList = scene.meshes;

+ 8 - 8
src/Tools/babylon.tools.ts

@@ -532,14 +532,6 @@
             var width: number;
             var height: number;
 
-            var scene = camera.getScene();
-            var previousCamera: Camera = null;
-
-            if (scene.activeCamera !== camera) {
-                previousCamera = scene.activeCamera;
-                scene.activeCamera = camera;
-            }
-
             //If a precision value is specified
             if (size.precision) {
                 width = Math.round(engine.getRenderWidth() * size.precision);
@@ -571,6 +563,14 @@
                 Tools.Error("Invalid 'size' parameter !");
                 return;
             }
+			
+			var scene = camera.getScene();
+            var previousCamera: Camera = null;
+			
+			if (scene.activeCamera !== camera) {
+                previousCamera = scene.activeCamera;
+                scene.activeCamera = camera;
+            }
 
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
             var texture = new RenderTargetTexture("screenShot", size, scene, false, false);