BeksOmega / looping-layout

A looping LayoutManager for the Android RecyclerView.
Apache License 2.0
271 stars 16 forks source link

Crash, when changing Adapter's item count #61

Closed niveuseverto closed 3 years ago

niveuseverto commented 3 years ago

:bug: Describe

Exception raised when changing adapter item count to less value (if current position is >= new item count)

java.lang.IndexOutOfBoundsException: Invalid item position 30(30). Item count:28 ... layout:com.bekawestberg.loopinglayout.library.LoopingLayoutManager@676e127, context:android.view.ContextThemeWrapper@6eff01c
...
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6145)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at com.bekawestberg.loopinglayout.library.LoopingLayoutManager.createViewForIndex(LoopingLayoutManager.kt:355)
        at com.bekawestberg.loopinglayout.library.LoopingLayoutManager.onLayoutChildren(LoopingLayoutManager.kt:206)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
        at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1897)
        at androidx.recyclerview.widget.RecyclerView$1.run(RecyclerView.java:414)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
        at android.view.Choreographer.doCallbacks(Choreographer.java:796)
        at android.view.Choreographer.doFrame(Choreographer.java:727)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

:snail: Steps to reproduce

  1. Set 30 items to adapter
  2. Scroll to 29-30 position
  3. Set 28 items to adapter
  4. Call notifyItemRangeRemoved or notifyDataSetChanged

:butterfly: Expected behavior

No crash, possible to jump to last position.

:beetle: Other info

Seems like this is problem in saving/restoring RecyclerView state.

:bee: Requested assignment

I'm just reporting this problem. Have little experience with kotlin.

BeksOmega commented 3 years ago

Hello @niveuseverto Thank you for reporting this issue! I think your diagnosis of the problem is correct :D I definitely want to get this fixed, but I'm a bit busy with other projects at the moment, so it may be a while before I circle back to this.

Thank you again for reporting, and providing all of the detailed information (console logs, repro steps, etc). That info makes issues a lot easier to debug, so I always really appreciate it =)

Best wishes, --Beka

niveuseverto commented 3 years ago

@BeksOmega, I will try to settle time to add test with this case, don't sure that will be able to fix it

BeksOmega commented 3 years ago

Closed via #62