turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
779 stars 126 forks source link

ArithmeticException: divide by zero at ScrollingUtilities #91

Open betri28 opened 7 years ago

betri28 commented 7 years ago

Crash in some device:

  1. Model: LG-F160 Board: Gv Android API: 16 Android OS: 4.1.2

  2. Model: SM-G928C Board: Universal7420 Android API: 24 Android OS: 7.0

Here is log stack traces:

Exception java.lang.ArithmeticException: divide by zero
com.turingtechnologies.materialscrollbar.ScrollingUtilities.scrollToPositionAtProgress (ScrollingUtilities.java:119)
com.turingtechnologies.materialscrollbar.MaterialScrollBar.onDown (MaterialScrollBar.java:701)
com.turingtechnologies.materialscrollbar.TouchScrollBar$2.onTouch (TouchScrollBar.java:72)
android.view.View.dispatchTouchEvent (View.java:7154)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2170)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1905)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2176)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1919)
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent (PhoneWindow.java:2196)
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1572)
android.app.Activity.dispatchTouchEvent (Activity.java:2623)
android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:71)
android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:71)
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent (PhoneWindow.java:2145)
android.view.View.dispatchPointerEvent (View.java:7339)
android.view.ViewRootImpl.deliverPointerEvent (ViewRootImpl.java:3207)
android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:3146)
android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:4197)
android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:4176)
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:4268)
android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:179)
android.view.InputEventReceiver.nativeConsumeBatchedInputEvents (InputEventReceiver.java)
android.view.InputEventReceiver.consumeBatchedInputEvents (InputEventReceiver.java:171)
android.view.ViewRootImpl.doConsumeBatchedInput (ViewRootImpl.java:4247)
android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run (ViewRootImpl.java:4287)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:725)
android.view.Choreographer.doCallbacks (Choreographer.java:555)
android.view.Choreographer.doFrame (Choreographer.java:523)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:711)
android.os.Handler.handleCallback (Handler.java:615)
android.os.Handler.dispatchMessage (Handler.java:92)
android.os.Looper.loop (Looper.java:137)
android.app.ActivityThread.main (ActivityThread.java:4904)
java.lang.reflect.Method.invokeNative (Method.java)
turing-tech commented 7 years ago

When does this occur?

betri28 commented 7 years ago

I dont know when. I see that in crash report in firebase. I read your code in ScrollingUtilities, exception divide by zero at

layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / scrollPosState.rowHeight,
                    -(exactItemPos % scrollPosState.rowHeight));

scrollPosState.rowHeight = 0 at some potision. Can rowHeight = 0 ???

turing-tech commented 7 years ago

This may happen if materialScrollBar.recyclerView.getChildAt(0); returns null. Could I see the adapter for the recyclerView in question?

SjoerdvGestel commented 7 years ago

i'm having the same issue

turing-tech commented 6 years ago

Could I see the adapter for the recyclerView in question?

DranzerX commented 6 years ago

@turing-tech, i'm having the same issue in firebase logs too.

As adapter I use FastAdapter library by mikepenz:

protected ModelAdapter<Model, Item> itemAdapter = new ModelAdapter<>(this::toItem);
protected ItemAdapter<ProgressItem> footerAdapter = ItemAdapter.items();
protected FastAdapter<Item> fastAdapter = FastAdapter.with(Arrays.asList(itemAdapter, footerAdapter));

...

recyclerView.setAdapter(fastAdapter);
dragScrollBar.setRecyclerView(recyclerView);

Both sub-adapters can be empty.

turing-tech commented 6 years ago

@DranzerX I am still unable to replicate. I have copied the given code verbatim.

Could you give me an updated stacktrace with the latest version of the library? The one originally provided no longer matches the code.

DranzerX commented 6 years ago

@turing-tech here it is:

Fatal Exception: java.lang.ArithmeticException
divide by zero
com.turingtechnologies.materialscrollbar.ScrollingUtilities.scrollToPositionAtProgress (ScrollingUtilities.java:129)
com.turingtechnologies.materialscrollbar.MaterialScrollBar.setTouchIntercept (MaterialScrollBar.java:745)
com.turingtechnologies.materialscrollbar.DragScrollBar.setTouchIntercept (DragScrollBar.java:65)
com.turingtechnologies.materialscrollbar.DragScrollBar$$Lambda$1.onTouch (Unknown Source:4)
android.view.View.dispatchTouchEvent (View.java:11784)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2968)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2647)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2974)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2604)
com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:549)
com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1953)
android.app.Activity.dispatchTouchEvent (Activity.java:3548)
android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:68)
android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:68)
com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:502)
android.view.View.dispatchPointerEvent (View.java:12027)
android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:5240)
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:5030)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4544)
android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4597)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4563)
android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:4690)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4571)
android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:4747)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4544)
android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4597)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4563)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4571)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4544)
android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:7121)
android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:7095)
android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:7056)
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:7277)
android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:192)
android.os.MessageQueue.nativePollOnce (MessageQueue.java)
android.os.MessageQueue.next (MessageQueue.java:379)
android.os.Looper.loop (Looper.java:144)
android.app.ActivityThread.main (ActivityThread.java:7425)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

I can't reproduce this too, but I see ~100 crashes per 20k runs in firebase crashlytics, on different devices and different versions of Android. Maybe dragbar incorrectly stay visible when the adapter is empty and user interaction cause this problem?

turing-tech commented 6 years ago

Push the newest version and see what happens. I basically just wrapped it in a try catch, as I'm hoping it's just an edge case that happens when the view first appears. If reports of misbehaviour continue to occur I'll look into it further.

DranzerX commented 6 years ago

@turing-tech thank you, I'll try.