Skip to content

Commit

Permalink
Add a few sanity checks when loading poses, for issue #58
Browse files Browse the repository at this point in the history
  • Loading branch information
joepal1976 committed Nov 9, 2022
1 parent 4bf9adc commit 5df3051
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mpfb/ui/applypose/operators/loadpartial.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def execute(self, context):
from mpfb.ui.applypose.applyposepanel import POSES_PROPERTIES
name = POSES_PROPERTIES.get_value("available_partials", entity_reference=context.scene)

if not name:
self.report({'ERROR'}, "Must select a valid pose name")
return {'FINISHED'}

rig_type = RigService.identify_rig(armature_object)
if "default" in rig_type:
rig_type = "default"
Expand All @@ -48,6 +52,10 @@ def execute(self, context):
absolute_file_path = bpy.path.abspath(os.path.join(pose_root, name + ".json"))
_LOG.debug("absolute_file_path", absolute_file_path)

if not os.path.exists(absolute_file_path):
self.report({'ERROR'}, "The selected pose '" + name + "' for rig type '" + rigtype + mode + "' does not exist as file. You should probably report this as a bug.")
return {'FINISHED'}

pose = dict()

with open(absolute_file_path, "r") as json_file:
Expand Down
10 changes: 10 additions & 0 deletions src/mpfb/ui/applypose/operators/loadpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def execute(self, context):
from mpfb.ui.applypose.applyposepanel import POSES_PROPERTIES
name = POSES_PROPERTIES.get_value("available_poses", entity_reference=context.scene)

name = str(name).strip()

if not name:
self.report({'ERROR'}, "Must select a valid pose name")
return {'FINISHED'}

rig_type = RigService.identify_rig(armature_object)
if "default" in rig_type:
rig_type = "default"
Expand All @@ -52,6 +58,10 @@ def execute(self, context):
absolute_file_path = bpy.path.abspath(os.path.join(pose_root, name + ".json"))
_LOG.debug("absolute_file_path", absolute_file_path)

if not os.path.exists(absolute_file_path):
self.report({'ERROR'}, "The selected pose '" + name + "' for rig type '" + rigtype + mode + "' does not exist as file. You should probably report this as a bug.")
return {'FINISHED'}

pose = dict()

with open(absolute_file_path, "r") as json_file:
Expand Down

0 comments on commit 5df3051

Please sign in to comment.