From e135057ad92bf4d1dc7f0598abd01bf61e6ff20a Mon Sep 17 00:00:00 2001 From: Aly Serry Date: Wed, 12 Aug 2026 08:46:25 +0300 Subject: [PATCH] Guard against crash when opening a file before the media player is ready browseMediapath(), OpenAddFilesToPlaylistDialog(), and SyncplayClient.openFile() all dereferenced self._player without checking it for None. The player stays None until it finishes launching and connects back to Syncplay (see SyncplayClient.initPlayer), so any of the following crash if they happen before that: - opening a file from the File menu - adding files to the playlist from the File menu - double-clicking a file already in the playlist (playlistItemClicked -> openFile), the same way even with a working player if you click fast enough right after startup All three hit: AttributeError: 'NoneType' object has no attribute 'customOpenDialog' AttributeError: 'NoneType' object has no attribute 'openFile' This matches the crashes reported in #787 and #786. Guard all three call sites with the existing playerIsNotReady() helper and show a message instead of crashing. --- syncplay/client.py | 4 ++++ syncplay/messages_en.py | 1 + syncplay/ui/gui.py | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/syncplay/client.py b/syncplay/client.py index 894222598..06013a72b 100755 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -619,6 +619,10 @@ def openFile(self, filePath, resetPosition=False, fromUser=False): self.playlist.loadPlaylistFromFile(filePath, resetPosition) return + if self.playerIsNotReady(): + self.ui.showErrorMessage(getMessage("player-not-ready-error")) + return + self.playlist.openedFile() self._player.openFile(filePath, resetPosition) if resetPosition: diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index b2864fad2..16a5c870b 100644 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -139,6 +139,7 @@ "mpv-failed-advice": "The reason mpv cannot start may be due to the use of unsupported command line arguments or an unsupported version of mpv.", "player-file-open-error": "Player failed opening file", "player-path-error": "Player path is not set properly. Supported players are: mpv, mpv.net, VLC, MPC-HC, MPC-BE, mplayer2, and IINA", + "player-not-ready-error": "Media player is not ready yet. Please wait for it to finish starting up and try again.", "hostname-empty-error": "Hostname can't be empty", "empty-error": "{} can't be empty", # Configuration "media-player-error": "Media player error: \"{}\"", # Error line diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 8518626f7..4343f1c63 100755 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -1067,6 +1067,9 @@ def getInitialMediaDirectory(self, includeUserSpecifiedDirectories=True): @needsClient def browseMediapath(self): + if self._syncplayClient.playerIsNotReady(): + self.showErrorMessage(getMessage("player-not-ready-error")) + return if self._syncplayClient._player.customOpenDialog == True: self._syncplayClient._player.openCustomOpenDialog() return @@ -1096,6 +1099,9 @@ def browseMediapath(self): @needsClient def OpenAddFilesToPlaylistDialog(self): + if self._syncplayClient.playerIsNotReady(): + self.showErrorMessage(getMessage("player-not-ready-error")) + return if self._syncplayClient._player.customOpenDialog == True: self._syncplayClient._player.openCustomOpenDialog() return