From 5398afe5da9001ce24768b4d32cc0fae4a314974 Mon Sep 17 00:00:00 2001 From: SceneMax3D Date: Sun, 21 Jul 2024 22:41:36 +0300 Subject: [PATCH] thread safe run --- .../java/com/scenemaxeng/FullscreenGameActivity.java | 5 ++--- .../com/scenemaxeng/common/types/AssetsMapping.java | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/scenemaxeng/FullscreenGameActivity.java b/src/main/java/com/scenemaxeng/FullscreenGameActivity.java index de20a29..85e8c6b 100644 --- a/src/main/java/com/scenemaxeng/FullscreenGameActivity.java +++ b/src/main/java/com/scenemaxeng/FullscreenGameActivity.java @@ -200,10 +200,9 @@ private void startGame() { showJmeProjectorFragment(); File targetFile = new File(this.targetScriptPath); if(targetFile.exists()) { - new Handler().postDelayed(new Runnable() { + runOnUiThread(new Runnable() { @Override public void run() { - String code = Util.readFile(targetFile); code=code.replaceFirst("^canvas\\.size\\s+((?\\d+),(?\\d+))","");; code = applyMacros(code); @@ -211,7 +210,7 @@ public void run() { getJmeFragment().runScript(code, workingFolder); app = (SceneMaxApp) getJmeFragment().getJmeApplication(); } - },500); + }); } } diff --git a/src/main/java/com/scenemaxeng/common/types/AssetsMapping.java b/src/main/java/com/scenemaxeng/common/types/AssetsMapping.java index e625d20..ac1f74a 100644 --- a/src/main/java/com/scenemaxeng/common/types/AssetsMapping.java +++ b/src/main/java/com/scenemaxeng/common/types/AssetsMapping.java @@ -418,7 +418,9 @@ private JSONObject getAssetsResourcesFolderIndex(String path) { try { String data = loadFileFromAssets(path); - return new JSONObject(data); + if(data != null && data.length() > 0) { + return new JSONObject(data); + } } catch (Exception e) { e.printStackTrace(); @@ -432,8 +434,10 @@ private JSONObject getResourcesFolderIndex(String path) { try { File f = new File(path); if(f.exists()) { - String json = Util.readFile(f); - return new JSONObject(json); + String data = Util.readFile(f); + if(data != null && data.length() > 0) { + return new JSONObject(data); + } } } catch (Exception e) { e.printStackTrace();