From 8bf6e5b5ee3aa69f01a4d7800782525eadf75417 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 2 Jan 2013 16:51:09 +0100 Subject: [PATCH] Remove preDispatch call. Fix possible segfault for ID table lookup. --- android/native/jni/input_android.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c index 9307ac19aa..fb0375879a 100644 --- a/android/native/jni/input_android.c +++ b/android/native/jni/input_android.c @@ -30,7 +30,7 @@ #define PRESSED_LEFT(x, y) ((-0.80f > x) && (x >= -1.00f)) #define PRESSED_RIGHT(x, y) ((0.80f < x) && (x <= 1.00f)) -#define MAX_DEVICE_IDS 50 +#define MAX_DEVICE_IDS 0x100 static unsigned pads_connected; static uint64_t state[MAX_PADS]; @@ -101,21 +101,21 @@ static void android_input_poll(void *data) AInputEvent* event = NULL; AInputQueue_getEvent(android_app->inputQueue, &event); - if (AInputQueue_preDispatchEvent(android_app->inputQueue, event)) - continue; - int32_t handled = 1; int source = AInputEvent_getSource(event); int id = AInputEvent_getDeviceId(event); + // Some Android devices tend to have really high values for device ID. E.g. 0 and 0x10001. + // We assume that the lower 8 bits of ID are unique. + int lut_id = id & 0xff; int type_event = AInputEvent_getType(event); - int state_id = state_device_ids[id]; + int state_id = state_device_ids[lut_id]; if(state_id == -1) { - state_id = state_device_ids[id] = pads_connected++; + state_id = state_device_ids[lut_id] = pads_connected++; input_autodetect_setup(state_id, id, source); }