TeamNewPipe / NewPipe

A libre lightweight streaming front-end for Android.
https://newpipe.net
GNU General Public License v3.0
31.31k stars 3.04k forks source link

Crash in lists (ViewHolder views not attached) #4475

Open andrewshadura opened 4 years ago

andrewshadura commented 4 years ago

Checklist

Steps to reproduce the bug

  1. Set up peertube.debian.social as the peertube instance
  2. Open Trending/Local/whatever
  3. Attempt to scroll beyond the last element

Actual behaviour

Crash (see below).

Expected behavior

I’d expect more video thumbnails to appear.

Logs

Exception

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7080)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6680)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


Device info

Stypox commented 4 years ago

This was already reported a while ago, and there is unfortunately no way to reproduce. It has nothing to do with PeerTube in particular, but just with lists. If there will be a way to reproduce this consistently this issue can be reopened, but as of now there is none. Thank you for the report anyway! ;-)

andrewshadura commented 4 years ago

Well, it happens here all the time, each time, is there any way I can use this to help?

opusforlife2 commented 4 years ago

Ah. Then we probably need logs, don't we, @Stypox?

Stypox commented 4 years ago

I don't think logs would help. I already tried fixing this bug but failed, since NewPipe is already doing what the error suggests to do:

Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)

opusforlife2 commented 4 years ago

So it's an OS bug that NewPipe can't work around. Okay. Sorry, @andrewshadura.

andrewshadura commented 4 years ago

Can’t we at least catch the exception in a better way?

Stypox commented 4 years ago

The issue is, that exception does not come from NewPipe's code, but from some other library code. Therefore catching the error and ignoring it would probably not solve anything, because the app would be put in an unstable state where something is wrong and would crash again with another kind of crash.

andrewshadura commented 4 years ago

I’ve just found an interesting fact. First of all, I’m using a remote to navigate the list. Second, it only happens when I navigate it in a particular way. The screen is a grid of 2½ rows by 5 columns. For some reason, only 12 thumbnails are displayed:

The crash usually happens when I press "down" while the last element is focused (but not every time, I haven’t found the exact 100% reproducible sequence).

I’m wondering, can the crash be somehow related with the fact fewer items have been preloaded than the grid expects? I don’t understand it from the code, how is the number of items to preload determined?

Stypox commented 4 years ago

Thank you for the further information. This might be related to the issue about infinite loading in lists when the initial number of items is smaller than the screen size (I read about that issue earlier today, but now can't find it anymore. @opusforlife2 can you find it?)

how is the number of items to preload determined?

That's service-dependent, i.e. it depends on the implementation of the service in NewPipeExtractor.

opusforlife2 commented 4 years ago

@Stypox #1974.

532910 commented 3 years ago

Looks like I have the same issue scrolling down manualy created Bookmarked Playlist.

532910 commented 3 years ago

I was able to reproduce this twice. Steps:

  1. Open a Bookmarked Playlist with a lot of videos i.e. scrollable
  2. Tap one of the latest videos and watch it till the end (possibly in fullscreen mode). You cat FF of course.
  3. Press back to return to the playlist.
  4. Scroll to the top of the playlist.
eternal-sorrow commented 3 years ago

Is there anything that can be done? Like for example handle this exception and throw another, adding more details in the error message that can be useful to identify what causes this error?

This crash does not happen very often, but it happens every now and then, always when scrolling to the top of some kind of list. I wasn't able to reliably reproduce it, but that doesn't mean there's no way to debug this.

Ojd2000 commented 3 years ago

Hello, I was able to reproduce the bug similarly to what said by @532910:

I was able to reproduce this twice. Steps:

1. Open a Bookmarked Playlist with a lot of videos i.e. scrollable

2. Tap one of the latest videos and watch it till the end (possibly in fullscreen mode). You cat FF of course.

3. Press back to return to the playlist.

4. Scroll to the top of the playlist.

My steps to reproduce:

  1. Open a custom scrollable playlist

  2. Open any video, provided that you leave items in the list to scroll up later

  3. In any order:

    • Reproduce the video, if not already;
    • Enter fullscreen (no matter how long for);
    • Skip to any point of the video, in order to stay sufficiently distant from the initial point.
  4. Exit fullscreen;

  5. Go back to the list without pausing or closing the video;

  6. Scroll up;

  7. It should crash.

Hope this can help.

Stypox commented 3 years ago

@Ojd2000 thank you for providing some detailed instructions, though I can't reproduce even with those

hlintala commented 3 years ago

I can reproduce this crash following way:

  1. Open a custom scrollable playlist (i.e. playlist long enough that you cannot see all playlist items at the same time in either portrait mode or landscape mode)
  2. Start playing any video in popup window and wait until video starts playing
  3. Scroll down so that first playlist item is not visible on the screen
  4. Rotate your device such a way that NewPipe switches from landscape to portrait mode or portrait to landscape
  5. Scroll up to the top of the playlist
  6. Newpipe crashes

Hopefully this way crash is reproducible for you.

tsiflimagas commented 3 years ago

@hlintala I faced this crash too a few times recently, but I couldn't find a certain way to reproduce it and report. It seems that you did, I can confirm this way the crash should occur.

hlintala commented 3 years ago

@tsiflimagas

I have also discovered that you can step away from crashing state by returning back to bookmarked playlist view.

By the way in a crashing state you can see name of the playlist at top left corner (sometimes hidden by icon of playlist item)

litetex commented 2 years ago

Closed #7486 and #7512 in favor of this. The manual from #7512 looks promising (even tough I didn't check it).

Stypox commented 2 years ago

@litetex I could reproduce with @hlintala method, I tried to find the root source of this bug a month ago or so, but even then the crash is inside Androd libraries and that doesn't give useful information

litetex commented 2 years ago

@Stypox

We found the problem: https://github.com/TeamNewPipe/NewPipe/issues/3368#issuecomment-1013541937 🥳

sajanki commented 2 years ago

I am not sure if this error I have just got is related but I am posting it here anyway.

This is the first crash I have experienced with this version of NewPipe, so I am reporting it

Exception

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7297)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:7325)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)


I always run the latest version, so I will see if it still happens after an upgrade.

gardockt commented 2 years ago

By following steps mentioned above, I can consistently reproduce the crash on version 0.22.1:

Exception

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7297)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)


litetex commented 2 years ago

Not sure if the above problem is just a random error, but the problem might be caused by the header: In #7659 I rewrote the header so that it's supplied dynamically: https://github.com/TeamNewPipe/NewPipe/pull/7659/files#diff-d075c1aaf95acf093a7feaa093198bfbc9c4d5b479e2b57effdaf7a9e74448d9R265

However since the header is only built once (e.g. https://github.com/TeamNewPipe/NewPipe/pull/7659/files#diff-7bdacd85bbbb0481247ad81e0e17840e930afaa9b7d3741e7d947d621e62f44dR69-R85) it can happen that the same object is supplied multiple times. This shouldn't happen because there can only be ONE header (not sure why it tries to attach the same header a second time).

I'm pretty sure that there is a race condition (maybe inside RecyclerView itself) or something similar. I think we can only fix this by reworking the Channel-/Playlist-/Related-ItemsFragment so that it can work with multiple headers which might cause other problems.

I think we should only invest time here if it occurs more often.

janAtHub commented 2 years ago

I face this issue multiple times a day by scrolling through local playlists. The descriptions above fits to the error behavior I witness. I am using the playlist feature extensively and the app crashes regularly when using local playlists on the home screen. Especially when opening and watching a video on the end of a playlist, closing the video, deleting it and scrolling up. (No accurate description, I know and I am sorry, but it seems to be a bit random) So

"...if it occurs more often."

seems to be a question on how one is using the app.

Exception

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7297)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

opusforlife2 commented 2 years ago

@litetex ^

triallax commented 2 years ago

Reported in https://github.com/TeamNewPipe/NewPipe/issues/8164 with 0.22.1.

AudricV commented 2 years ago

In #7659 I rewrote the header so that it's supplied dynamically

It seems the changes have been not made for local lists: in LocalItemListAdapter, which is used by BaseLocalListFragment (the base abstract class of LocalPlaylistFragment (used for local playlists), StatisticsPlaylistFragment (used for the history) and BookmarkFragment (used for the Bookmarked Playlists tab)), I can see the old code removed or the one before the changes of #7659 in this Adapter.

@litetex Do you want to take care of this or should it be done by someone else?

litetex commented 2 years ago

Someone else can do it if he/she wants :)

I might also pick it up when nobody want's to fix it ;)

wildwestrom commented 1 year ago

I believe I may be encountering the same bug. It usually happens when I scroll up, but not all the time.

Exception

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7297)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7898)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

ghost commented 1 year ago

It just happened to me on 0.24.1

DieBauer commented 1 year ago

Happened to me as well

Exception

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7297)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8757)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)


smellymoo commented 1 year ago

My way of recreating bug is more useful to debug the problem:

1: goto a playlist 2: delete an item 3: scroll to top of playlist (probably past the top?)