|
@@ -1,6 +1,7 @@
|
|
|
var engine = null;
|
|
|
var canas = null;
|
|
|
var scene = null;
|
|
|
+var globalParent = null;
|
|
|
|
|
|
handleException = function(parent, e) {
|
|
|
parent.utils.showError(e.message, e);
|
|
@@ -8,15 +9,17 @@ handleException = function(parent, e) {
|
|
|
console.error(e);
|
|
|
}
|
|
|
|
|
|
-fastEval = function(code, parent) {
|
|
|
+fastEval = function(code) {
|
|
|
var head = document.getElementsByTagName('head')[0];
|
|
|
var script = document.createElement('script');
|
|
|
script.setAttribute('type', 'text/javascript');
|
|
|
- script.onerror = (message) => {
|
|
|
- parent.utils.showError(message);
|
|
|
- }
|
|
|
|
|
|
- script.innerHTML = code;
|
|
|
+ script.innerHTML = `try {
|
|
|
+ ${code};
|
|
|
+ }
|
|
|
+ catch(e) {
|
|
|
+ handleException(globalParent, e);
|
|
|
+ }`;
|
|
|
|
|
|
head.appendChild(script);
|
|
|
}
|
|
@@ -30,6 +33,7 @@ compileAndRun = function(parent, fpsLabel) {
|
|
|
|
|
|
try {
|
|
|
parent.menuPG.hideWaitDiv();
|
|
|
+ globalParent = parent;
|
|
|
|
|
|
if (!BABYLON.Engine.isSupported()) {
|
|
|
parent.utils.showError("Your browser does not support WebGL. Please, try to update it, or install a compatible one.", null);
|
|
@@ -89,7 +93,7 @@ compileAndRun = function(parent, fpsLabel) {
|
|
|
engine = createDefaultEngine();
|
|
|
scene = new BABYLON.Scene(engine);
|
|
|
var runScript = null;
|
|
|
- fastEval("runScript = function(scene, canvas) {" + code + "}", parent);
|
|
|
+ fastEval("runScript = function(scene, canvas) {" + code + "}");
|
|
|
runScript(scene, canvas);
|
|
|
|
|
|
parent.zipTool.ZipCode = "var engine = " + defaultEngineZip + ";\r\nvar scene = new BABYLON.Scene(engine);\r\n\r\n" + code;
|
|
@@ -104,14 +108,14 @@ compileAndRun = function(parent, fpsLabel) {
|
|
|
}
|
|
|
|
|
|
// Create engine
|
|
|
- fastEval("engine = " + createEngineFunction + "()", parent);
|
|
|
+ fastEval("engine = " + createEngineFunction + "()");
|
|
|
if (!engine) {
|
|
|
parent.utils.showError("createEngine function must return an engine.", null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Execute the code
|
|
|
- fastEval(code, parent);
|
|
|
+ fastEval(code);
|
|
|
|
|
|
if (!scene) {
|
|
|
parent.utils.showError(createSceneFunction + " function must return a scene.", null);
|