Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArithmeticException: divide by zero at ScrollingUtilities #91

Open
betri28 opened this issue Apr 24, 2017 · 10 comments
Open

ArithmeticException: divide by zero at ScrollingUtilities #91

betri28 opened this issue Apr 24, 2017 · 10 comments

Comments

@betri28
Copy link

betri28 commented Apr 24, 2017

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
Copy link
Owner

When does this occur?

@betri28
Copy link
Author

betri28 commented Apr 25, 2017

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
Copy link
Owner

turing-tech commented Apr 26, 2017

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

@SjoerdvGestel
Copy link

i'm having the same issue

@turing-tech
Copy link
Owner

Could I see the adapter for the recyclerView in question?

@DranzerX
Copy link

@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
Copy link
Owner

@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
Copy link

DranzerX commented Jul 2, 2018

@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
Copy link
Owner

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
Copy link

DranzerX commented Jul 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants