pedrovgs / DraggablePanel

Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.
Apache License 2.0
2.99k stars 605 forks source link

Facing Array index out of bound Exception #31

Open Amritpal33 opened 9 years ago

Amritpal33 commented 9 years ago

Hi pedrovgs/Fiddl,

I am facing Arrayindex out of bound on frquently seeking the seekbar of Player.

Tested on Device Nexus 5 and Samsung S4 Android version: kitkat

Here are the Logs:

12-10 19:45:01.340: E/AndroidRuntime(1411): java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1011) 12-10 19:45:01.340: E/AndroidRuntime(1411): at com.github.pedrovgs.DraggableView.onInterceptTouchEvent(DraggableView.java:290) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1859) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 12-10 19:45:01.340: E/AndroidRuntime(1411): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068) 12-10 19:45:01.340: E/AndroidRuntime(1411): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.app.Activity.dispatchTouchEvent(Activity.java:2458) 12-10 19:45:01.340: E/AndroidRuntime(1411): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.View.dispatchPointerEvent(View.java:7886) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5585) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5631) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.Choreographer.doFrame(Choreographer.java:542) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.os.Handler.handleCallback(Handler.java:733) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.os.Handler.dispatchMessage(Handler.java:95) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.os.Looper.loop(Looper.java:136) 12-10 19:45:01.340: E/AndroidRuntime(1411): at android.app.ActivityThread.main(ActivityThread.java:5001) 12-10 19:45:01.340: E/AndroidRuntime(1411): at java.lang.reflect.Method.invokeNative(Native Method) 12-10 19:45:01.340: E/AndroidRuntime(1411): at java.lang.reflect.Method.invoke(Method.java:515) 12-10 19:45:01.340: E/AndroidRuntime(1411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 12-10 19:45:01.340: E/AndroidRuntime(1411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 12-10 19:45:01.340: E/AndroidRuntime(1411): at dalvik.system.NativeStart.main(Native Me

Please let me know how can i fix this.

Thanks !

pedrovgs commented 9 years ago

I need time to review this. Let me check it this weekend ;)

Fiddl3 commented 9 years ago

This happens to me too on some devices... I don't think this is bug in DraggableView, but there is simple solution - check pointerCount and if count > 1 return false :

  @Override public boolean onInterceptTouchEvent(MotionEvent ev) {
  ...

    if (action == MotionEvent.ACTION_CANCEL || 
        action == MotionEvent.ACTION_UP  || 
        ev.getPointerCount() > 1) {
      viewDragHelper.cancel();
      return false;
    }

  ...
  }
Amritpal33 commented 9 years ago

Hi Fiddl3, The Method is already written in the similar passion , and the crash is still there.

Fiddl3 commented 9 years ago

You can always catch exception and return false but you should debug ViewDragHelper.shouldInterceptTouchEvent() method because it appears that MotionEvent is changing in for loop and this cause exception, because before loop PointerCount must be grater than 1, but in second pass of for loop NullPointerException appears in line :

final float dx = x - mInitialMotionX[pointerId];
Fiddl3 commented 9 years ago

please try this branch https://github.com/Fiddl3/DraggablePanel/tree/viewDragHelper_issue if it fix this bug I'll create pull request

pedrovgs commented 9 years ago

Do you know if this bug is still reproducible?

Fiddl3 commented 9 years ago

For now I'm using try...catch to silence this exception, but I really don't know why it is happening even with new instance on event...

pedrovgs commented 9 years ago

@Amritpal33, @Fiddl3 can we close this issue? Or can you still reproduce it with the last library version?