Skip to content

Commit

Permalink
Merge pull request wheremyfoodat#401 from wheremyfoodat/rdeepfired
Browse files Browse the repository at this point in the history
Android: Toast when ROM fails to load
  • Loading branch information
wheremyfoodat authored Feb 10, 2024
2 parents b256c89 + a797297 commit f5d3cc9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/jni_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,4 +25,4 @@ public class AlberDriver {
public static native void setShaderJitEnabled(boolean enable);

static { System.loadLibrary("Alber"); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand All @@ -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());
}

Expand Down Expand Up @@ -150,4 +177,4 @@ public ConsoleLayout getLayout() {
public String getBackendName() {
return "OpenGL";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit f5d3cc9

Please sign in to comment.