diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2025-09-30 18:02:44 -0500 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2025-09-30 18:03:05 -0500 |
| commit | ecb6dbbfd3d4e9ce7fb2b9e17675448773828761 (patch) | |
| tree | 1e07b5a7185d3b1d3bf1809099fd38ce72cfcbc1 /Source | |
| parent | 0c89c00d8bf798091e9a2d1e9abe444743cf6bae (diff) | |
WiimoteReal: Use GetEnvForThread within IORead/IOWrite calls to fix real Wii remotes on Android.
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp | 35 | ||||
| -rw-r--r-- | Source/Core/Core/HW/WiimoteReal/IOAndroid.h | 2 |
2 files changed, 19 insertions, 18 deletions
diff --git a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp index 507cacf006..84d9c2615a 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp @@ -53,17 +53,16 @@ WiimoteAndroid::~WiimoteAndroid() // Connect to a Wiimote with a known address. bool WiimoteAndroid::ConnectInternal() { - m_env = IDCache::GetEnvForThread(); + auto* const env = IDCache::GetEnvForThread(); - jfieldID payload_field = m_env->GetStaticFieldID(s_adapter_class, "wiimotePayload", "[[B"); + jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "wiimotePayload", "[[B"); jobjectArray payload_object = - reinterpret_cast<jobjectArray>(m_env->GetStaticObjectField(s_adapter_class, payload_field)); - m_java_wiimote_payload = - (jbyteArray)m_env->GetObjectArrayElement(payload_object, m_mayflash_index); + 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 = m_env->GetStaticMethodID(s_adapter_class, "input", "(I)I"); - m_output_func = m_env->GetStaticMethodID(s_adapter_class, "output", "(I[BI)I"); + m_input_func = env->GetStaticMethodID(s_adapter_class, "input", "(I)I"); + m_output_func = env->GetStaticMethodID(s_adapter_class, "output", "(I[BI)I"); is_connected = true; @@ -84,26 +83,30 @@ bool WiimoteAndroid::IsConnected() const // zero = error int WiimoteAndroid::IORead(u8* buf) { - int read_size = m_env->CallStaticIntMethod(s_adapter_class, m_input_func, m_mayflash_index); + auto* const env = IDCache::GetEnvForThread(); + + int read_size = env->CallStaticIntMethod(s_adapter_class, m_input_func, m_mayflash_index); if (read_size > 0) { - jbyte* java_data = m_env->GetByteArrayElements(m_java_wiimote_payload, nullptr); + jbyte* java_data = env->GetByteArrayElements(m_java_wiimote_payload, nullptr); memcpy(buf + 1, java_data, std::min(MAX_PAYLOAD - 1, read_size)); buf[0] = 0xA1; - m_env->ReleaseByteArrayElements(m_java_wiimote_payload, java_data, 0); + env->ReleaseByteArrayElements(m_java_wiimote_payload, java_data, 0); } return read_size <= 0 ? read_size : read_size + 1; } int WiimoteAndroid::IOWrite(u8 const* buf, size_t len) { - jbyteArray output_array = m_env->NewByteArray(len); - jbyte* output = m_env->GetByteArrayElements(output_array, nullptr); + auto* const env = IDCache::GetEnvForThread(); + + jbyteArray output_array = env->NewByteArray(len); + jbyte* output = env->GetByteArrayElements(output_array, nullptr); memcpy(output, buf, len); - m_env->ReleaseByteArrayElements(output_array, output, 0); - int written = m_env->CallStaticIntMethod(s_adapter_class, m_output_func, m_mayflash_index, - output_array, len); - m_env->DeleteLocalRef(output_array); + env->ReleaseByteArrayElements(output_array, output, 0); + int written = + env->CallStaticIntMethod(s_adapter_class, m_output_func, m_mayflash_index, output_array, len); + env->DeleteLocalRef(output_array); return written; } diff --git a/Source/Core/Core/HW/WiimoteReal/IOAndroid.h b/Source/Core/Core/HW/WiimoteReal/IOAndroid.h index c29c1de869..7581a6dbd1 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOAndroid.h +++ b/Source/Core/Core/HW/WiimoteReal/IOAndroid.h @@ -31,8 +31,6 @@ private: int m_mayflash_index; bool is_connected = true; - JNIEnv* m_env; - jmethodID m_input_func; jmethodID m_output_func; |
