playback: fix crash with state restore [#89]

Fix an esoteric crash with queue synchronization during the playback
restore process.

Auxio will attempt to re-synchronize the queue index whenever it is
desynchronized, however during the check for if it's desynchronized,
Auxio would do a direct index of the queue, which could result in a
crash in situations where the desynchronized index is outside of the
queue bounds.

Fix this by replacing that unprotected access with a protected access,
which not only fixes the crash but also still correctly detects
desynchronization in that case.

Resolves #89.
This commit is contained in:
OxygenCobalt 2022-03-06 19:25:48 -07:00
parent 1b791074ec
commit b5b8767f46
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 7 additions and 3 deletions

View file

@ -1,7 +1,6 @@
# Changelog
## dev [v2.2.2 or 2.3.0]
#### What's New
- New spanish translations and metadata [courtesy of n-berenice]
@ -16,6 +15,7 @@ from the system theme was used [#80]
- Fixed incorrect track numbers when the tag was formatted as NN/TT [#88]
- Fixed years deliberately set as "0" showing up as "No Date"
- Fixed headset management unexpectedly starting audio when the app initially opens
- Fixed crash that would occur during a playback restore with specific queue states [#89]
#### What's Changed
- All cover art is now cropped to a 1:1 aspect ratio

View file

@ -40,6 +40,8 @@ import org.oxycblt.auxio.util.logE
*
* All access should be done with [PlaybackStateManager.getInstance].
* @author OxygenCobalt
*
* TODO: Rework this to possibly handle gapless playback and more refined queue management.
*/
class PlaybackStateManager private constructor() {
// Playback
@ -594,7 +596,9 @@ class PlaybackStateManager private constructor() {
* Do a sanity check to make sure that the index lines up with the current song.
*/
private fun doIndexSanityCheck() {
if (mSong != null && mSong != mQueue[mIndex]) {
// Note: Be careful with how we handle the queue since a possible index desync
// could easily result in an OOB issue.
if (mSong != null && mSong != mQueue.getOrNull(mIndex)) {
val correctedIndex = mQueue.wobblyIndexOfFirst(mIndex, mSong)
if (correctedIndex > -1) {

View file

@ -9,7 +9,6 @@ While I do like adding new behavior/UI customizations, these will be looked at m
## Feature Additions and UI Changes
These arent as likely to be accepted. As I said, I do not want Auxio to become overly bloated with features that are rarely used, therefore I only tend to accept features that:
- Benefit **my own** usage
- Are in line with Auxio's purpose as a music player
@ -25,3 +24,4 @@ Feel free to fork Auxio to add your own feature set however.
- Gapless Playback [#35] (Technical issues, may change in the future)
- Reduce leading instrument [#45] (Technical issues, Out of scope)
- Opening music through a provider [#30] (Out of scope)
- Cuesheet support [#83]