diff --git a/src/jni_driver.cpp b/src/jni_driver.cpp index d962f23eb..1af325e33 100644 --- a/src/jni_driver.cpp +++ b/src/jni_driver.cpp @@ -81,10 +81,12 @@ AlberFunction(void, Finalize)(JNIEnv* env, jobject obj) { AlberFunction(jboolean, HasRomLoaded)(JNIEnv* env, jobject obj) { return romLoaded; } -AlberFunction(void, LoadRom)(JNIEnv* env, jobject obj, jstring path) { +AlberFunction(jboolean, LoadRom)(JNIEnv* env, jobject obj, jstring path) { const char* pathStr = env->GetStringUTFChars(path, nullptr); romLoaded = emulator->loadROM(pathStr); env->ReleaseStringUTFChars(path, pathStr); + + return romLoaded; } AlberFunction(void, LoadLuaScript)(JNIEnv* env, jobject obj, jstring script) { diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/AlberDriver.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/AlberDriver.java index 00b7842b0..7367a447e 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/AlberDriver.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/AlberDriver.java @@ -9,7 +9,7 @@ public class AlberDriver { public static native void Initialize(); public static native void RunFrame(int fbo); public static native boolean HasRomLoaded(); - public static native void LoadRom(String path); + public static native boolean LoadRom(String path); public static native void Finalize(); public static native void KeyDown(int code); @@ -25,4 +25,4 @@ public class AlberDriver { public static native void setShaderJitEnabled(boolean enable); static { System.loadLibrary("Alber"); } -} \ No newline at end of file +} diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java index c39b36b3b..41492962b 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java @@ -2,20 +2,23 @@ import static android.opengl.GLES32.*; +import android.content.Context; import android.content.res.Resources; import android.graphics.Rect; import android.opengl.GLSurfaceView; +import android.os.Handler; import android.util.Log; +import android.widget.Toast; import com.panda3ds.pandroid.AlberDriver; +import com.panda3ds.pandroid.data.SMDH; import com.panda3ds.pandroid.data.config.GlobalConfig; +import com.panda3ds.pandroid.data.game.GameMetadata; import com.panda3ds.pandroid.utils.Constants; import com.panda3ds.pandroid.utils.GameUtils; import com.panda3ds.pandroid.utils.PerformanceMonitor; import com.panda3ds.pandroid.view.renderer.ConsoleRenderer; import com.panda3ds.pandroid.view.renderer.layout.ConsoleLayout; import com.panda3ds.pandroid.view.renderer.layout.DefaultScreenLayout; -import com.panda3ds.pandroid.data.SMDH; -import com.panda3ds.pandroid.data.game.GameMetadata; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -25,9 +28,11 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer, ConsoleRenderer private int screenWidth, screenHeight; private int screenTexture; public int screenFbo; + private final Context context; - PandaGlRenderer(String romPath) { + PandaGlRenderer(Context context, String romPath) { super(); + this.context = context; this.romPath = romPath; screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels; @@ -40,8 +45,8 @@ protected void finalize() throws Throwable { if (screenTexture != 0) { glDeleteTextures(1, new int[] {screenTexture}, 0); } - - if (screenFbo != 0) { + + if (screenFbo != 0) { glDeleteFramebuffers(1, new int[] {screenFbo}, 0); } @@ -84,7 +89,29 @@ public void onSurfaceCreated(GL10 unused, EGLConfig config) { AlberDriver.Initialize(); AlberDriver.setShaderJitEnabled(GlobalConfig.get(GlobalConfig.KEY_SHADER_JIT)); - AlberDriver.LoadRom(romPath); + + // If loading the ROM failed, display an error message and early exit + if (!AlberDriver.LoadRom(romPath)) { + // Get a handler that can be used to post to the main thread + Handler mainHandler = new Handler(context.getMainLooper()); + + Runnable runnable = new Runnable() { + @Override + public void run() { + Toast + .makeText( + context, "Failed to load ROM! Make sure it's a valid 3DS ROM and that storage permissions are configured properly.", + Toast.LENGTH_LONG + ) + .show(); + } + }; + mainHandler.post(runnable); + + GameMetadata game = GameUtils.getCurrentGame(); + GameUtils.removeGame(game); + return; + } // Load the SMDH byte[] smdhData = AlberDriver.GetSmdh(); @@ -93,12 +120,12 @@ public void onSurfaceCreated(GL10 unused, EGLConfig config) { } else { SMDH smdh = new SMDH(smdhData); Log.i(Constants.LOG_TAG, "Loaded rom SDMH"); - Log.i(Constants.LOG_TAG, String.format("Are you playing '%s' published by '%s'", smdh.getTitle(), smdh.getPublisher())); + Log.i(Constants.LOG_TAG, String.format("You are playing '%s' published by '%s'", smdh.getTitle(), smdh.getPublisher())); GameMetadata game = GameUtils.getCurrentGame(); GameUtils.removeGame(game); GameUtils.addGame(GameMetadata.applySMDH(game, smdh)); } - + PerformanceMonitor.initialize(getBackendName()); } @@ -150,4 +177,4 @@ public ConsoleLayout getLayout() { public String getBackendName() { return "OpenGL"; } -} \ No newline at end of file +} diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java index c813294c7..e3023fcbb 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java @@ -21,7 +21,7 @@ public PandaGlSurfaceView(Context context, String romPath) { if (Debug.isDebuggerConnected()) { setDebugFlags(DEBUG_LOG_GL_CALLS); } - renderer = new PandaGlRenderer(romPath); + renderer = new PandaGlRenderer(getContext(), romPath); setRenderer(renderer); }