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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user