Skip to content

Commit

Permalink
Add exception handling so a malformed media file does nto crash Lutri…
Browse files Browse the repository at this point in the history
…s, and does not prevent you from setting a new media.

Resolves #5474
  • Loading branch information
danieljohnson2 committed May 13, 2024
1 parent 075b531 commit 5959768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lutris/gui/config/game_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,13 @@ def _set_image(self, image_format, image_button):
service_media = self.service_medias[image_format]
game_slug = self.slug or (self.game.slug if self.game else "")
media_path = resolve_media_path(service_media.get_possible_media_paths(game_slug))
image = ScaledImage.new_from_media_path(media_path, service_media.config_ui_size, scale_factor)
image_button.set_image(image)
try:
image = ScaledImage.new_from_media_path(media_path, service_media.config_ui_size, scale_factor)
image_button.set_image(image)
except Exception as ex:
# We need to survive nasty data in the media files, so the user can replace
# them.
logger.exception("Unable to load media '%s': %s", image_format, ex)

def _get_runner_dropdown(self):
runner_liststore = self._get_runner_liststore()
Expand Down
11 changes: 10 additions & 1 deletion lutris/gui/widgets/cellrenderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gi

from lutris.util.jobs import schedule_at_idle
from lutris.util.log import logger

gi.require_version("PangoCairo", "1.0")

Expand Down Expand Up @@ -535,7 +536,15 @@ def _get_cached_surface_by_path(self, widget, path, size=None, preserve_aspect_r
def _get_surface_by_path(self, widget, path, size=None, preserve_aspect_ratio=True):
cell_size = size or (self.media_width, self.media_height)
scale_factor = widget.get_scale_factor() if widget else 1
return get_scaled_surface_by_path(path, cell_size, scale_factor, preserve_aspect_ratio=preserve_aspect_ratio)
try:
return get_scaled_surface_by_path(
path, cell_size, scale_factor, preserve_aspect_ratio=preserve_aspect_ratio
)
except Exception as ex:
# We need to survive nasty data in the media files, so the user can replace
# them.
logger.exception("Unable to load media '%s': %s", path, ex)
return None


def _on_media_cached_invalidated() -> None:
Expand Down

0 comments on commit 5959768

Please sign in to comment.