Browse Source

Starting renderLoop only on scene loaded, stopping on scene unload.
Testing if an activeCamera is set before trying to attach control since user can specify a default camera on his sceneLoadedCallback.

Nicolas Obré 11 years ago
parent
commit
21ce0b85e3
1 changed files with 5 additions and 3 deletions
  1. 5 3
      Babylon/Tools/babylon.filesInput.js

+ 5 - 3
Babylon/Tools/babylon.filesInput.js

@@ -18,8 +18,6 @@ var BABYLON = BABYLON || {};
         this.additionnalRenderLoopLogicCallback = p_additionnalRenderLoopLogicCallback;
         this.textureLoadingCallback = p_textureLoadingCallback;
         this.startingProcessingFilesCallback = p_startingProcessingFilesCallback;
-
-        this.engine.runRenderLoop(renderFunction);
     };
 
     // elementToMonitor is the HTML element that will listen to drag'n'drop events
@@ -95,6 +93,7 @@ var BABYLON = BABYLON || {};
             // If a ".babylon" file has been provided
             if (sceneFileToLoad) {
                 if (that.currentScene) {
+                    that.engine.stopRenderLoop();
                     that.currentScene.dispose();
                 }
 
@@ -104,10 +103,13 @@ var BABYLON = BABYLON || {};
                     // Wait for textures and shaders to be ready
                     that.currentScene.executeWhenReady(function () {
                         // Attach camera to canvas inputs
-                        that.currentScene.activeCamera.attachControl(that.canvas);
+                        if (that.currentScene.activeCamera) {
+                            that.currentScene.activeCamera.attachControl(that.canvas);
+                        }
                         if (that.sceneLoadedCallback) {
                             that.sceneLoadedCallback(sceneFileToLoad, that.currentScene);
                         }
+                        that.engine.runRenderLoop(renderFunction);
                     });
                 }, function (progress) {
                     if (that.progressCallback) {