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:
Arkadiusz Fal
2025-11-19 18:01:02 +01:00
parent e882d0264b
commit 4b577a296b
4 changed files with 15 additions and 8 deletions

View File

@@ -458,7 +458,7 @@ struct ControlsOverlay: View {
Menu {
audioTrackPicker
} label: {
Text(player.availableAudioTracks[player.selectedAudioTrackIndex].displayLanguage)
Text(player.selectedAudioTrack?.displayLanguage ?? "Original")
.frame(maxWidth: 240, alignment: .trailing)
}
.transaction { t in t.animation = .none }
@@ -468,7 +468,7 @@ struct ControlsOverlay: View {
.frame(height: 40)
#else
ControlsOverlayButton(focusedField: $focusedField, field: .audioTrack) {
Text(player.availableAudioTracks[player.selectedAudioTrackIndex].displayLanguage)
Text(player.selectedAudioTrack?.displayLanguage ?? "Original")
.frame(maxWidth: 320)
}
.contextMenu {