mirror of
https://github.com/yattee/yattee.git
synced 2025-11-20 17:02:21 +00:00
Fix array index out of bounds crash in audio track handling
This commit addresses crashes caused by race conditions when accessing audio track arrays: - MPVBackend.swift: Use safe index clamping to prevent array out of bounds crashes when selecting audio tracks - PlayerModel.swift: Add selectedAudioTrack computed property for thread-safe audio track access - ControlsOverlay.swift: Use safe accessor with "Original" fallback label - PlaybackSettings.swift: Use safe accessor with "Original" fallback label This fix resolves approximately 37% of crashes (23 out of 62 crash logs) that were caused by index out of range errors in MPVBackend.playStream at line 345.
This commit is contained in:
@@ -338,11 +338,11 @@ final class MPVBackend: PlayerBackend {
|
||||
|
||||
// Handle streams with multiple audio tracks
|
||||
if !stream.audioTracks.isEmpty {
|
||||
if stream.selectedAudioTrackIndex >= stream.audioTracks.count {
|
||||
stream.selectedAudioTrackIndex = 0
|
||||
}
|
||||
// Ensure the index is within bounds to prevent race conditions
|
||||
let safeIndex = min(max(0, stream.selectedAudioTrackIndex), stream.audioTracks.count - 1)
|
||||
stream.selectedAudioTrackIndex = safeIndex
|
||||
|
||||
stream.audioAsset = AVURLAsset(url: stream.audioTracks[stream.selectedAudioTrackIndex].url)
|
||||
stream.audioAsset = AVURLAsset(url: stream.audioTracks[safeIndex].url)
|
||||
let fileToLoad = self.model.musicMode ? stream.audioAsset.url : stream.videoAsset.url
|
||||
let audioTrack = self.model.musicMode ? nil : stream.audioAsset.url
|
||||
|
||||
|
||||
Reference in New Issue
Block a user