Skip to content

fix(player): Fix scaleX being NaN on minimize to background app switch#12952

Merged
theimpulson merged 3 commits intodevfrom
fix/NaN-on-minimize
Dec 29, 2025
Merged

fix(player): Fix scaleX being NaN on minimize to background app switch#12952
theimpulson merged 3 commits intodevfrom
fix/NaN-on-minimize

Conversation

@TobiGr
Copy link
Contributor

@TobiGr TobiGr commented Dec 26, 2025

What is it?

  • Bugfix (user facing)

Description of the changes in your PR

This aims to fix the following Exception which might occour when watching a live stream and switching the app while 'minimize to backgorund' is enabled:

java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
	at android.view.View.sanitizeFloatPropertyValue(View.java:17479)
	at android.view.View.sanitizeFloatPropertyValue(View.java:17453)
	at android.view.View.setScaleX(View.java:16822)
	at org.schabi.newpipe.views.ExpandableSurfaceView.onLayout(ExpandableSurfaceView.java:71)

For the fill stacktrace and description, see #12925 (comment) and #12955.

scaleX is set in onMeasure() in which width could be 0 in theory and this leading to a division by zero of a float which results in an assignment of Float.NaN.

The set aspectRatio is, but must not be not finite, which causes an assignment of Float.NaN.

Remarks

Note for reviewers

The second finding actually fixes the crash while the first does not as noted in #12955. But I'd like to keep both safeguards. I was initially expecting to find a View that was not hidden or destroyed. The aspect ration seems to be not finite which means that the video width and height retrieved from Exoplayer are 0. This could mean that the player is not detached or destroyed as expected. However, I am unable to reproduce this crash and this is more a symptom fix than actually taking a shot at the root cause. If someone is able to reproduce this, please take a look at it!

Fixes the following issue(s)

This is a potential fix for the stacktrace given in #12925 (comment)

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.

Due diligence

@TobiGr TobiGr added bug Issue is related to a bug player Issues related to any player (main, popup and background) labels Dec 26, 2025
@github-actions github-actions bot added the size/small PRs with less than 50 changed lines label Dec 26, 2025
@TobiGr TobiGr marked this pull request as ready for review December 27, 2025 08:32
@TobiGr TobiGr marked this pull request as draft December 28, 2025 10:25
@TobiGr
Copy link
Contributor Author

TobiGr commented Dec 29, 2025

@theimpulson This PR fixes crashes which have not been reported in the 0.28.0 release and only with recent nightly releases. We did not touch any related files recently which leads me to the suspicion that a dependecy update might be the cause for this issue. Any ideas?

@theimpulson
Copy link
Member

@theimpulson This PR fixes crashes which have not been reported in the 0.28.0 release and only with recent nightly releases. We did not touch any related files recently which leads me to the suspicion that a dependecy update might be the cause for this issue. Any ideas?

I think it might be exoplayer. I see this on exoplayer 2.19.0 changelog:

Make MediaCodecVideoRenderer report a VideoSize with a width and height of 0 when the renderer is disabled. Player.Listener.onVideoSizeChanged is called accordingly when Player.getVideoSize() changes. With this change, ExoPlayer's video size with MediaCodecVideoRenderer has a width and height of 0 when Player.getCurrentTracks does not support video, or the size of the supported video track is not yet determined.

This aims to fix the following Exception which might occour when watching a live stream and switching the app while 'minimize to backgorund' is enabled:

java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
	at android.view.View.sanitizeFloatPropertyValue(View.java:17479)
	at android.view.View.sanitizeFloatPropertyValue(View.java:17453)
	at android.view.View.setScaleX(View.java:16822)
	at org.schabi.newpipe.views.ExpandableSurfaceView.onLayout(ExpandableSurfaceView.java:71)

scaleX is set in onMeasure() in which width could be 0 in theory and this leading to a division by zero of a float which results in an assignment of Float.NaN.
If the video's hieght is 0, the aspectRatio is set to Float.NaN which can cause further issues. Do not assign invalid values for the aspectRatio.
@TobiGr TobiGr force-pushed the fix/NaN-on-minimize branch from c62db16 to b0e766d Compare December 29, 2025 15:36
@TobiGr TobiGr marked this pull request as ready for review December 29, 2025 15:36
@TobiGr
Copy link
Contributor Author

TobiGr commented Dec 29, 2025

Thanks. That's the cause. I kept the previous two commits to ensure no bad values are used and added a commit to tackle the cause where it should be.

The interesting question is why I am not able to reproduce the error on the emulator or my phone. But I don't think we have to answer that 😅

@TobiGr TobiGr requested a review from theimpulson December 29, 2025 15:38
@TobiGr TobiGr force-pushed the fix/NaN-on-minimize branch from b0e766d to 465979e Compare December 29, 2025 15:41
@theimpulson
Copy link
Member

LGTM

@theimpulson theimpulson merged commit 824fc8f into dev Dec 29, 2025
5 checks passed
@theimpulson theimpulson deleted the fix/NaN-on-minimize branch December 29, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue is related to a bug player Issues related to any player (main, popup and background) size/small PRs with less than 50 changed lines

Projects

None yet

2 participants