Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fusion: provide better logging for validate saver crash due type error (
Browse files Browse the repository at this point in the history
#6082)

* OP-7467 - move get_tool_resolution to classmethod

Doesn't make much sense to have it outside of class. Debugging of it is impossible there (because of missing logger). Imho.

* OP-7467 - add check for frame

Limits uncaught error when resolution info is None, which could happen when saver is not connected.

* OP-7467 - remove debugging messages

* OP-7467 - enhance get_invalid

Handle exception to select broken saver in the Publisher UI.

* OP-7467 - refactor check

Here it makes more sense. We try to run some expression, but it might still result in None.

---------

Co-authored-by: Libor Batek <[email protected]>
Co-authored-by: Jakub Ježek <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 0a862a2 commit 4709676
Showing 1 changed file with 63 additions and 52 deletions.
115 changes: 63 additions & 52 deletions openpype/hosts/fusion/plugins/publish/validate_saver_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,6 @@
from openpype.hosts.fusion.api import comp_lock_and_undo_chunk


def get_tool_resolution(tool, frame):
"""Return the 2D input resolution to a Fusion tool
If the current tool hasn't been rendered its input resolution
hasn't been saved. To combat this, add an expression in
the comments field to read the resolution
Args
tool (Fusion Tool): The tool to query input resolution
frame (int): The frame to query the resolution on.
Returns:
tuple: width, height as 2-tuple of integers
"""
comp = tool.Composition

# False undo removes the undo-stack from the undo list
with comp_lock_and_undo_chunk(comp, "Read resolution", False):
# Save old comment
old_comment = ""
has_expression = False
if tool["Comments"][frame] != "":
if tool["Comments"].GetExpression() is not None:
has_expression = True
old_comment = tool["Comments"].GetExpression()
tool["Comments"].SetExpression(None)
else:
old_comment = tool["Comments"][frame]
tool["Comments"][frame] = ""

# Get input width
tool["Comments"].SetExpression("self.Input.OriginalWidth")
width = int(tool["Comments"][frame])

# Get input height
tool["Comments"].SetExpression("self.Input.OriginalHeight")
height = int(tool["Comments"][frame])

# Reset old comment
tool["Comments"].SetExpression(None)
if has_expression:
tool["Comments"].SetExpression(old_comment)
else:
tool["Comments"][frame] = old_comment

return width, height


class ValidateSaverResolution(
pyblish.api.InstancePlugin, OptionalPyblishPluginMixin
):
Expand Down Expand Up @@ -87,19 +38,79 @@ def process(self, instance):

@classmethod
def get_invalid(cls, instance):
resolution = cls.get_resolution(instance)
saver = instance.data["tool"]
try:
resolution = cls.get_resolution(instance)
except PublishValidationError:
resolution = None
expected_resolution = cls.get_expected_resolution(instance)
if resolution != expected_resolution:
saver = instance.data["tool"]
return [saver]

@classmethod
def get_resolution(cls, instance):
saver = instance.data["tool"]
first_frame = instance.data["frameStartHandle"]
return get_tool_resolution(saver, frame=first_frame)
return cls.get_tool_resolution(saver, frame=first_frame)

@classmethod
def get_expected_resolution(cls, instance):
data = instance.data["assetEntity"]["data"]
return data["resolutionWidth"], data["resolutionHeight"]

@classmethod
def get_tool_resolution(cls, tool, frame):
"""Return the 2D input resolution to a Fusion tool
If the current tool hasn't been rendered its input resolution
hasn't been saved. To combat this, add an expression in
the comments field to read the resolution
Args
tool (Fusion Tool): The tool to query input resolution
frame (int): The frame to query the resolution on.
Returns:
tuple: width, height as 2-tuple of integers
"""
comp = tool.Composition

# False undo removes the undo-stack from the undo list
with comp_lock_and_undo_chunk(comp, "Read resolution", False):
# Save old comment
old_comment = ""
has_expression = False

if tool["Comments"][frame] not in ["", None]:
if tool["Comments"].GetExpression() is not None:
has_expression = True
old_comment = tool["Comments"].GetExpression()
tool["Comments"].SetExpression(None)
else:
old_comment = tool["Comments"][frame]
tool["Comments"][frame] = ""
# Get input width
tool["Comments"].SetExpression("self.Input.OriginalWidth")
if tool["Comments"][frame] is None:
raise PublishValidationError(
"Cannot get resolution info for frame '{}'.\n\n "
"Please check that saver has connected input.".format(
frame
)
)

width = int(tool["Comments"][frame])

# Get input height
tool["Comments"].SetExpression("self.Input.OriginalHeight")
height = int(tool["Comments"][frame])

# Reset old comment
tool["Comments"].SetExpression(None)
if has_expression:
tool["Comments"].SetExpression(old_comment)
else:
tool["Comments"][frame] = old_comment

return width, height

0 comments on commit 4709676

Please sign in to comment.