Skip to content

Commit

Permalink
Prevent crash in colorImage if file could not be found
Browse files Browse the repository at this point in the history
Fixes CURA-3NF (Sentry)
  • Loading branch information
nallath committed Apr 25, 2022
1 parent 7341da5 commit 091c2ac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions UM/ColorImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from PyQt6.QtQuick import QQuickPaintedItem
from PyQt6.QtSvg import QSvgRenderer
from UM.Application import Application
from UM.Logger import Logger


# This is meant as a potential replacement for RecolorImage.
# As we had issues with upgrading to qt6 on windows with the shader, this was developed as an alternative
Expand All @@ -23,8 +25,12 @@ def __init__(self, parent = None):
def _updateSVG(self) -> None:
if not self._source or self._source.toLocalFile() == "":
return
with open(self._source.toLocalFile(), "rb") as f:
self._svg_data = f.read()
try:
with open(self._source.toLocalFile(), "rb") as f:
self._svg_data = f.read()
except FileNotFoundError:
Logger.log("w", f"Unable to find image located at {self._source.toLocalFile()}")
return
self._svg_data = self._svg_data.replace(b"<svg ", b"<svg fill=\"%s\" " % self._color.name().encode("utf-8"))
self._renderer = QSvgRenderer(self._svg_data)
self.update()
Expand Down

0 comments on commit 091c2ac

Please sign in to comment.