facebookarchive/wit-android-sdk

ArrayIndexOutOfBoundException on Marshmallow

Opened this issue · 3 comments

I'm getting this error on android 6.0 while everything goes smoothly in Lollipop:

E/AndroidRuntime: FATAL EXCEPTION: Thread-1512
Process: com.example.desh.examplerestaurantwitapp, PID: 19852
java.lang.ArrayIndexOutOfBoundsException: length=12800; index=12800
at ai.wit.sdk.WitMic$SamplesReaderThread.short2byte(WitMic.java:227)
at ai.wit.sdk.WitMic$SamplesReaderThread.run(WitMic.java:207)
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab47c940

I'm getting the same, but this is when I try to force 64 bit devices to use the 32 bit library

Still occuring to me, just updated to 6.0 and got this problem. Has anyone found a solution for it yet?

It is a problem with method short2byte inside WitMic.java.

As variable "bytes" is an array of bytes and a byte (8 bits) is double size of a short (16 bits) and the arrays "bytes" and "buffer" are both the same max length (readBufferSize) java throws a ArrayIndexOutOfBoundException when the loop reaches bytes[readBufferSize].

Solution is to double the max length of array "bytes" at line 172 (giving the last version of WitMic.java at the time i'm writing this) modifying it from:
byte[] bytes = new byte[readBufferSize];
to

byte[] bytes = new byte[readBufferSize * 2];

After doing this change you will have to compile again in order to generate wit.sdk again. Anyway i'm attaching my WitMic.java in case it helps.

WitMic.zip