From f5888a7c56dd333f5f0a99e5669af9d500574a10 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 23 Oct 2020 13:42:28 -0400 Subject: [PATCH] Android crash fixes --- .../mindustry/android/AndroidLauncher.java | 42 ++++++++++--------- core/src/mindustry/editor/MapView.java | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/android/src/mindustry/android/AndroidLauncher.java b/android/src/mindustry/android/AndroidLauncher.java index 7400bd37a8..b3ee4723cc 100644 --- a/android/src/mindustry/android/AndroidLauncher.java +++ b/android/src/mindustry/android/AndroidLauncher.java @@ -166,29 +166,33 @@ public class AndroidLauncher extends AndroidApplication{ }}); checkFiles(getIntent()); + try{ + //new external folder + Fi data = Core.files.absolute(getContext().getExternalFilesDir(null).getAbsolutePath()); + Core.settings.setDataDirectory(data); - //new external folder - Fi data = Core.files.absolute(getContext().getExternalFilesDir(null).getAbsolutePath()); - Core.settings.setDataDirectory(data); + //move to internal storage if there's no file indicating that it moved + if(!Core.files.local("files_moved").exists()){ + Log.info("Moving files to external storage..."); - //move to internal storage if there's no file indicating that it moved - if(!Core.files.local("files_moved").exists()){ - Log.info("Moving files to external storage..."); - - try{ - //current local storage folder - Fi src = Core.files.absolute(Core.files.getLocalStoragePath()); - for(Fi fi : src.list()){ - fi.copyTo(data); + try{ + //current local storage folder + Fi src = Core.files.absolute(Core.files.getLocalStoragePath()); + for(Fi fi : src.list()){ + fi.copyTo(data); + } + //create marker + Core.files.local("files_moved").writeString("files moved to " + data); + Core.files.local("files_moved_103").writeString("files moved again"); + Log.info("Files moved."); + }catch(Throwable t){ + Log.err("Failed to move files!"); + t.printStackTrace(); } - //create marker - Core.files.local("files_moved").writeString("files moved to " + data); - Core.files.local("files_moved_103").writeString("files moved again"); - Log.info("Files moved."); - }catch(Throwable t){ - Log.err("Failed to move files!"); - t.printStackTrace(); } + }catch(Exception e){ + //print log but don't crash + Log.err(e); } } diff --git a/core/src/mindustry/editor/MapView.java b/core/src/mindustry/editor/MapView.java index a54c0f49b8..4db21dec66 100644 --- a/core/src/mindustry/editor/MapView.java +++ b/core/src/mindustry/editor/MapView.java @@ -321,7 +321,7 @@ public class MapView extends Element implements GestureListener{ } private boolean active(){ - return Core.scene.getKeyboardFocus() != null + return Core.scene != null && Core.scene.getKeyboardFocus() != null && Core.scene.getKeyboardFocus().isDescendantOf(ui.editor) && ui.editor.isShown() && tool == EditorTool.zoom && Core.scene.hit(Core.input.mouse().x, Core.input.mouse().y, true) == this;