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

NPE in ExtractorMediaSource, reproduced by quickly prepare and release the MediaSource #1914

Closed
eneim opened this issue Oct 8, 2016 · 10 comments
Labels

Comments

@eneim
Copy link
Contributor

eneim commented Oct 8, 2016

In short, here is my stacktrace:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.android.exoplayer2.source.MediaSource$Listener.onSourceInfoRefreshed(com.google.android.exoplayer2.Timeline, java.lang.Object)' on a null object reference
       at com.google.android.exoplayer2.source.ExtractorMediaSource.onSourceInfoRefreshed(ExtractorMediaSource.java:179)
       at com.google.android.exoplayer2.source.ExtractorMediaPeriod.maybeFinishPrepare(ExtractorMediaPeriod.java:408)
       at com.google.android.exoplayer2.source.ExtractorMediaPeriod.access$000(ExtractorMediaPeriod.java:49)
       at com.google.android.exoplayer2.source.ExtractorMediaPeriod$1.run(ExtractorMediaPeriod.java:120)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.os.HandlerThread.run(HandlerThread.java:61)
       at com.google.android.exoplayer2.util.PriorityHandlerThread.run(PriorityHandlerThread.java:40)

It happens when I have a list or video (RecyclerView), and scroll quickly through them (when a ViewHolder is attached to Window, it will prepare the Video with "playWhenReady = false").

Source code is from my library, so have no idea if it is OK to show it here. But let me know.

@ojw28 ojw28 added the bug label Oct 9, 2016
@ojw28
Copy link
Contributor

ojw28 commented Oct 9, 2016

If it's possible to provide an easy way to reproduce this as source (e.g. a patch for the demo app, or a link to some other open source demo app that reproduces the issue) that would be great.

The only way I can see this happening is if the ExtractorMediaSource has been released whilst one of its child ExtractorMediaPeriods has not, and I can't see an obvious way that can happen.

@mopsalarm
Copy link

I have the same issue in my app. Sadly, i dont know how to reproduce it, as it only happens on my users systems, never on mine. I am calling prepareSource() and stop() maybe multiple times on an exo player instance inside of a ViewPager.

@ojw28
Copy link
Contributor

ojw28 commented Oct 10, 2016

Which versions of ExoPlayer are you seeing this with? Unless you've shipped your app extremely recently I'd expect you to be seeing a different stack trace (even if only by the line numbers).

@mopsalarm
Copy link

2.0.0 and 2.0.2. I skipped the 2.0.1 release. I am putting daily/every-second-day builds out there.
The NPE occurres in Line 179 in ExtractorMediaSource.

@ojw28
Copy link
Contributor

ojw28 commented Oct 10, 2016

Could you point me to your app in Play Store? I'd be interested in trying to reproduce. Thanks!

@mopsalarm
Copy link

Sadly, it is not in the play store - but you can find the repository here: https://github.com/mopsalarm/Pr0/tree/1.111.4
In the current master version, i use a exo player version with an if (sourceListener != null) added.

The ExoPlayer is wrapped here https://github.com/mopsalarm/Pr0/blob/1.111.4/app/src/main/java/com/pr0gramm/app/ui/views/viewer/video/ExoVideoPlayer.java
The start() and stop() Methods might be called multiple times during the Lifetime of this class.

@ojw28
Copy link
Contributor

ojw28 commented Oct 10, 2016

@mopsalarm - I checked out master and switched the dependency back to vanilla ExoPlayer. Should that be sufficient to get the app into a state where it might reproduce the issue (albeit that reproducing might be difficult). Do you know in which fragment the issue occurs, and what browsing steps I'd need to take to get to that fragment in the app? If not, that might be something you could usefully log in future releases, if you fancy helping to chase this down.

@ojw28
Copy link
Contributor

ojw28 commented Oct 10, 2016

Actually, it reproduces relatively easily (e.g. within 5 minutes or so) if you unleash the monkey on your app, like:

adb shell monkey -p com.pr0gramm.app -v 500

(repeat until crash occurs).

@eneim
Copy link
Contributor Author

eneim commented Oct 11, 2016

@ojw28 I notice that in ExtractorMediaSource, It passes itself to a new ExtractorMediaPeriod in createPeriod but it has never been released in releasePeriod (see ExtractorMediaPeriod#release()), which I guess the cause for this issue. It can be seen that if a call to ExoPlayer#stop() is called before the source is prepared, it will throw an NPE.

ojw28 added a commit that referenced this issue Oct 11, 2016
playingPeriodHolder can be null in the case that the first
period is still being prepared. We need to make sure we
release the period that's being prepared in such cases,
which is loadingPeriodHolder.

Issue: #1914

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135793472
@ojw28 ojw28 closed this as completed Oct 11, 2016
@mopsalarm
Copy link

nice 👍

@google google locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants