Unverified Commit a7c5f11a authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #7449 from MatejFranceskin/pr-fix-jni-crash

Set Android Joystick native methods from JNI_OnLoad
parents 9d255f45 c829c6f8
...@@ -211,9 +211,7 @@ static JoystickManager *_manager = nullptr; ...@@ -211,9 +211,7 @@ static JoystickManager *_manager = nullptr;
//helper method //helper method
bool JoystickAndroid::init(JoystickManager *manager) { bool JoystickAndroid::init(JoystickManager *manager) {
if (_manager == nullptr) { _manager = manager;
setNativeMethods(manager);
}
//this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports //this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports
//instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change //instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change
...@@ -267,12 +265,10 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA) ...@@ -267,12 +265,10 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA)
} }
} }
void JoystickAndroid::setNativeMethods(JoystickManager *manager) void JoystickAndroid::setNativeMethods()
{ {
qCDebug(JoystickLog) << "Registering Native Functions"; qCDebug(JoystickLog) << "Registering Native Functions";
_manager = manager;
// REGISTER THE C++ FUNCTION WITH JNI // REGISTER THE C++ FUNCTION WITH JNI
JNINativeMethod javaMethods[] { JNINativeMethod javaMethods[] {
{"nativeUpdateAvailableJoysticks", "()V", reinterpret_cast<void *>(jniUpdateAvailableJoysticks)} {"nativeUpdateAvailableJoysticks", "()V", reinterpret_cast<void *>(jniUpdateAvailableJoysticks)}
......
...@@ -21,14 +21,14 @@ public: ...@@ -21,14 +21,14 @@ public:
static bool init(JoystickManager *manager); static bool init(JoystickManager *manager);
static void setNativeMethods();
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager); static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
private: private:
bool handleKeyEvent(jobject event); bool handleKeyEvent(jobject event);
bool handleGenericMotionEvent(jobject event); bool handleGenericMotionEvent(jobject event);
static void setNativeMethods(JoystickManager *manager);
virtual bool _open(); virtual bool _open();
virtual void _close(); virtual void _close();
virtual bool _update(); virtual bool _update();
......
...@@ -78,9 +78,12 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue) ...@@ -78,9 +78,12 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
#endif #endif
#if defined(__android__) && !defined(NO_SERIAL_LINK) #if defined(__android__)
#include <jni.h> #include <jni.h>
#include "JoystickAndroid.h"
#if !defined(NO_SERIAL_LINK)
#include "qserialport.h" #include "qserialport.h"
#endif
jint JNI_OnLoad(JavaVM* vm, void* reserved) jint JNI_OnLoad(JavaVM* vm, void* reserved)
{ {
...@@ -90,8 +93,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) ...@@ -90,8 +93,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return -1; return -1;
} }
#if !defined(NO_SERIAL_LINK)
QSerialPort::setNativeMethods(); QSerialPort::setNativeMethods();
#endif
JoystickAndroid::setNativeMethods();
return JNI_VERSION_1_6; return JNI_VERSION_1_6;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment