summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2026-02-28 16:16:20 -0500
committerGitHub <noreply@github.com>2026-02-28 16:16:20 -0500
commit63fc9d7ca34285cf9217a62abc0156f7ffbc6e80 (patch)
tree097f1010f4d3240b2de1df225e41f6cf5e0878af
parent1a08708a75f3b47540c33cc8cc07866caa4d2a3f (diff)
parent5a914e52477a9bd82824ee2453492255cc6304ce (diff)
Merge pull request #14425 from JosJuice/android-wiimote-crash
Android: Fix Wii Remote connection crashes
-rw-r--r--Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp
index bdc0a6fc42..e82f389a21 100644
--- a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp
+++ b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp
@@ -58,11 +58,28 @@ auto WiimoteScannerAndroid::FindAttachedWiimotes() -> FindResults
WiimoteAndroid::WiimoteAndroid(int index) : Wiimote(), m_mayflash_index(index)
{
+ auto* const env = IDCache::GetEnvForThread();
+
+ jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "wiimotePayload", "[[B");
+ jobjectArray payload_object =
+ reinterpret_cast<jobjectArray>(env->GetStaticObjectField(s_adapter_class, payload_field));
+ jobject java_wiimote_payload = env->GetObjectArrayElement(payload_object, m_mayflash_index);
+ m_java_wiimote_payload = reinterpret_cast<jbyteArray>(env->NewGlobalRef(java_wiimote_payload));
+
+ env->DeleteLocalRef(payload_object);
+ env->DeleteLocalRef(java_wiimote_payload);
+
+ // Get function pointers
+ m_input_func = env->GetStaticMethodID(s_adapter_class, "input", "(I)I");
+ m_output_func = env->GetStaticMethodID(s_adapter_class, "output", "(I[BI)I");
}
WiimoteAndroid::~WiimoteAndroid()
{
Shutdown();
+
+ auto* const env = IDCache::GetEnvForThread();
+ env->DeleteGlobalRef(m_java_wiimote_payload);
}
std::string WiimoteAndroid::GetId() const
@@ -81,17 +98,6 @@ bool WiimoteAndroid::ConnectInternal()
if (IsConnected())
return true;
- auto* const env = IDCache::GetEnvForThread();
-
- jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "wiimotePayload", "[[B");
- jobjectArray payload_object =
- reinterpret_cast<jobjectArray>(env->GetStaticObjectField(s_adapter_class, payload_field));
- m_java_wiimote_payload = (jbyteArray)env->GetObjectArrayElement(payload_object, m_mayflash_index);
-
- // Get function pointers
- m_input_func = env->GetStaticMethodID(s_adapter_class, "input", "(I)I");
- m_output_func = env->GetStaticMethodID(s_adapter_class, "output", "(I[BI)I");
-
// Test a write to see if a remote is actually connected to the DolphinBar.
constexpr u8 report[] = {WR_SET_REPORT | BT_OUTPUT,
u8(WiimoteCommon::OutputReportID::RequestStatus), 0};
@@ -149,5 +155,6 @@ void InitAdapterClass()
JNIEnv* env = IDCache::GetEnvForThread();
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/WiimoteAdapter");
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
+ env->DeleteLocalRef(adapter_class);
}
} // namespace WiimoteReal