Skip to content

Commit aafa2db

Browse files
authored
Fix crash in VideoView.requestEdrMode while quitting, #4328 (#4329)
This commit will: - Add a new isStopping property to PlayerCore - Change PlayerCore.trackListChanged to do nothing if the player is stopping or shutting down - Change PlayerCore.refreshEdrMode to do nothing if the player is stopping or shutting down
1 parent 813a8fc commit aafa2db

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

iina/PlayerCore.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ class PlayerCore: NSObject {
156156
/// Whether shutdown of this player has completed (mpv has shutdown).
157157
var isShutdown = false
158158

159+
/// Whether stopping of this player has been initiated.
160+
var isStopping = false
161+
159162
/// Whether mpv playback has stopped and the media has been unloaded.
160163
var isStopped = true
161164

@@ -660,6 +663,7 @@ class PlayerCore: NSObject {
660663
// initiated directly through mpv.
661664
guard !isStopped else { return }
662665
Logger.log("Stopping playback", subsystem: subsystem)
666+
isStopping = true
663667
mpv.command(.stop)
664668
}
665669

@@ -670,6 +674,7 @@ class PlayerCore: NSObject {
670674
func playbackStopped() {
671675
Logger.log("Playback has stopped", subsystem: subsystem)
672676
isStopped = true
677+
isStopping = false
673678
postNotification(.iinaPlayerStopped)
674679
}
675680

@@ -1481,6 +1486,7 @@ class PlayerCore: NSObject {
14811486
triedUsingExactSeekForCurrentFile = false
14821487
info.fileLoading = false
14831488
info.haveDownloadedSub = false
1489+
isStopping = false
14841490
isStopped = false
14851491
checkUnsyncedWindowOptions()
14861492
// generate thumbnails if window has loaded video
@@ -1546,8 +1552,10 @@ class PlayerCore: NSObject {
15461552
}
15471553

15481554
func trackListChanged() {
1549-
// Must not process track list changes if mpv is terminating.
1550-
guard !isShuttingDown else { return }
1555+
// No need to process track list changes if playback is being stopped. Must not process track
1556+
// list changes if mpv is terminating as accessing mpv once shutdown has been initiated can
1557+
// trigger a crash.
1558+
guard !isStopping, !isStopped, !isShuttingDown else { return }
15511559
Logger.log("Track list changed", subsystem: subsystem)
15521560
getTrackInfo()
15531561
getSelectedTracks()
@@ -1578,7 +1586,9 @@ class PlayerCore: NSObject {
15781586
func refreshEdrMode() {
15791587
guard mainWindow.loaded else { return }
15801588
DispatchQueue.main.async {
1581-
guard !self.isStopped else { return }
1589+
// No need to refresh if playback is being stopped. Must not attempt to refresh if mpv is
1590+
// terminating as accessing mpv once shutdown has been initiated can trigger a crash.
1591+
guard !self.isStopping, !self.isStopped, !self.isShuttingDown else { return }
15821592
self.mainWindow.videoView.refreshEdrMode()
15831593
}
15841594
}

0 commit comments

Comments
 (0)