Fixed exception at shutdown if the controllers are closed after the HIDDeviceManager is shutdown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp
index dd0edf1..e5af5ad 100644
--- a/src/hidapi/android/hid.cpp
+++ b/src/hidapi/android/hid.cpp
@@ -436,6 +436,12 @@ public:
g_JVM->AttachCurrentThread( &env, NULL );
pthread_setspecific( g_ThreadKey, (void*)env );
+ if ( !g_HIDDeviceManagerCallbackHandler )
+ {
+ LOGV( "Device open without callback handler" );
+ return false;
+ }
+
m_bIsWaitingForOpen = false;
m_bOpenResult = env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerOpen, m_nId );
ExceptionCheck( env, "BOpen" );
@@ -545,11 +551,18 @@ public:
g_JVM->AttachCurrentThread( &env, NULL );
pthread_setspecific( g_ThreadKey, (void*)env );
- jbyteArray pBuf = NewByteArray( env, pData, nDataLen );
- int nRet = env->CallIntMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerSendOutputReport, m_nId, pBuf );
- ExceptionCheck( env, "SendOutputReport" );
-
- env->DeleteLocalRef( pBuf );
+ int nRet = -1;
+ if ( g_HIDDeviceManagerCallbackHandler )
+ {
+ jbyteArray pBuf = NewByteArray( env, pData, nDataLen );
+ nRet = env->CallIntMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerSendOutputReport, m_nId, pBuf );
+ ExceptionCheck( env, "SendOutputReport" );
+ env->DeleteLocalRef( pBuf );
+ }
+ else
+ {
+ LOGV( "SendOutputReport without callback handler" );
+ }
return nRet;
}
@@ -560,10 +573,18 @@ public:
g_JVM->AttachCurrentThread( &env, NULL );
pthread_setspecific( g_ThreadKey, (void*)env );
- jbyteArray pBuf = NewByteArray( env, pData, nDataLen );
- int nRet = env->CallIntMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerSendFeatureReport, m_nId, pBuf );
- ExceptionCheck( env, "SendFeatureReport" );
- env->DeleteLocalRef( pBuf );
+ int nRet = -1;
+ if ( g_HIDDeviceManagerCallbackHandler )
+ {
+ jbyteArray pBuf = NewByteArray( env, pData, nDataLen );
+ nRet = env->CallIntMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerSendFeatureReport, m_nId, pBuf );
+ ExceptionCheck( env, "SendFeatureReport" );
+ env->DeleteLocalRef( pBuf );
+ }
+ else
+ {
+ LOGV( "SendFeatureReport without callback handler" );
+ }
return nRet;
}
@@ -587,6 +608,12 @@ public:
g_JVM->AttachCurrentThread( &env, NULL );
pthread_setspecific( g_ThreadKey, (void*)env );
+ if ( !g_HIDDeviceManagerCallbackHandler )
+ {
+ LOGV( "GetFeatureReport without callback handler" );
+ return -1;
+ }
+
{
hid_mutex_guard cvl( &m_cvLock );
if ( m_bIsWaitingForFeatureReport )
@@ -657,8 +684,11 @@ public:
g_JVM->AttachCurrentThread( &env, NULL );
pthread_setspecific( g_ThreadKey, (void*)env );
- env->CallVoidMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerClose, m_nId );
- ExceptionCheck( env, "Close" );
+ if ( g_HIDDeviceManagerCallbackHandler )
+ {
+ env->CallVoidMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerClose, m_nId );
+ ExceptionCheck( env, "Close" );
+ }
hid_mutex_guard dataLock( &m_dataLock );
m_vecData.clear();