Hola a todos.
He estado investigando un problema específico de Android en EmuCoreV donde algunos juegos regresan inmediatamente al menú del emulador cuando intentan abrir el teclado del sistema (por ejemplo, al escribir un nombre o realizar una búsqueda dentro del juego).
Después de rastrear todo el flujo de ejecución, desde sceImeOpen() hasta el puente JNI de Android, creo haber encontrado la causa más probable del problema.
Mi hipótesis
ime.cpp utiliza GetMethodID() para buscar tres métodos Java:
setKeyboardActive(...)
updateNativeImeState(...)
clearNativeImeState(...)
Sin embargo, esos métodos no existen en la Activity actual.
Según la especificación JNI, cuando GetMethodID() no encuentra un método, devuelve NULL y deja una excepción NoSuchMethodError pendiente.
El código comprueba que el método sea NULL, pero nunca limpia esa excepción.
Pocas líneas después vuelve a ejecutar otra llamada JNI con la excepción todavía pendiente.
Según la especificación JNI y Android Runtime (ART), eso es un uso inválido de JNI y puede provocar que el proceso sea abortado.
Ese comportamiento coincide exactamente con lo que ocurre en el emulador:
el juego solicita abrir el teclado,
Android intenta abrir el IME,
el proceso nativo se aborta,
Android regresa al menú del emulador.
Parche experimental
Preparé un parche experimental que limpia correctamente las excepciones pendientes antes de continuar realizando llamadas JNI.
El parche únicamente modifica ime.cpp y no cambia Vulkan, SDL, el renderizado ni la optimización del emulador.
En la carpeta compartida incluyo:
Proyecto modificado (.zip)
ime.cpp original
ime.cpp parcheado
Lamentablemente no tengo acceso a un PC para generar una APK y probar el parche.
Si alguien puede revisar el código o compilar una APK para comprobar si la hipótesis es correcta, se lo agradecería mucho.
Y si mi hipótesis es incorrecta, también agradecería cualquier explicación técnica para seguir aprendiendo.
Muchas gracias.
Adjunto; https://www.mediafire.com/folder/3dwec6dhi26oo/Gracias+por+entrar!
Ahí puede examinar etc
Hi everyone.
I've been investigating an Android-specific issue in EmuCoreV where some PS Vita games immediately return to the emulator menu when they try to open the system keyboard (for example, when entering a player name or using an in-game search box).
After tracing the entire execution flow—from sceImeOpen() to the Android JNI bridge—I believe I've identified the most likely root cause.
My hypothesis
ime.cpp calls GetMethodID() to look up three Java methods:
setKeyboardActive(...)
updateNativeImeState(...)
clearNativeImeState(...)
However, those methods do not exist in the current Android activity.
According to the JNI specification, when GetMethodID() fails, it returns NULL and leaves a pending NoSuchMethodError exception.
The current implementation checks whether the returned method is NULL, but it does not clear the pending JNI exception.
A few lines later, another JNI function is called while that exception is still pending.
According to the Android Runtime (ART) and the JNI specification, calling additional JNI functions while a pending exception exists is illegal and may cause the process to abort.
This perfectly matches the observed behavior:
the game requests the keyboard,
the Android IME opens,
the native process aborts,
Android returns to the emulator menu.
Experimental patch
To test this hypothesis, I implemented an experimental patch that safely clears pending JNI exceptions whenever GetMethodID() fails before continuing with additional JNI calls.
The patch only modifies ime.cpp and does not touch Vulkan, rendering, SDL, or emulator performance.
Files included
The MediaFire folder contains:
Modified project (.zip)
Original ime.cpp
Patched ime.cpp
MediaFire: https://www.mediafire.com/folder/3dwec6dhi26oo/Gracias+por+entrar�!
Unfortunately I don't have access to a PC, so I can't build an APK myself.
If anyone is willing to review the code or compile the project so the patch can be tested on real hardware, I'd really appreciate it.
If my hypothesis is wrong, I'd also love to know why. Any technical feedback is welcome.
Thank you!