浏览代码

UI: error messages in various places

error messages for Matrix from Curve and make_perpindicular
also error messages in schema
Joseph Brandenburg 6 月之前
父节点
当前提交
81edb0d58c
共有 4 个文件被更改,包括 38 次插入8 次删除
  1. 12 1
      misc_nodes.py
  2. 6 1
      readtree.py
  3. 15 5
      schema_solve.py
  4. 5 1
      utilities.py

+ 12 - 1
misc_nodes.py

@@ -1,5 +1,5 @@
 from .node_container_common import *
-from .base_definitions import MantisNode, NodeSocket
+from .base_definitions import MantisNode, NodeSocket, FLOAT_EPSILON
 from .xForm_containers import xFormArmature, xFormBone
 from .misc_nodes_socket_templates import *
 from math import pi, tau
@@ -279,8 +279,17 @@ class UtilityMatrixFromCurve(MantisNode):
             from .utilities import data_from_ribbon_mesh
             #
             num_divisions = self.evaluate_input("Total Divisions")
+            if num_divisions <= 0:
+                raise GraphError("The number of divisions in the curve must be 1 or greater.")
             m_index = self.evaluate_input("Matrix Index")
+            if m_index >= num_divisions:
+                prRed(m_index, num_divisions)
+                raise GraphError(f"{self} tried to get a matrix-index greater the total number of divisions."
+                                  "The matrix index starts at 0. You're probably off by +1.")
             spline_index = self.evaluate_input("Spline Index")
+            if spline_index > len(curve.data.splines)-1:
+                raise GraphError(f"{self} is attempting to read from a spline in {curve.name} that does not exist."
+                                  " Try and reduce the value of Spline Index.")
             splines_factors = [ [] for i in range (spline_index)]
             factors = [1/num_divisions*m_index, 1/num_divisions*(m_index+1)]
             splines_factors.append(factors)
@@ -288,6 +297,8 @@ class UtilityMatrixFromCurve(MantisNode):
             head=data[spline_index][0][0]
             tail= data[spline_index][0][1]
             axis = (tail-head).normalized()
+            if axis.length_squared < FLOAT_EPSILON:
+                raise RuntimeError(f"Failed to read the curve {curve.name}.")
             normal=data[spline_index][2][0]
             # make sure the normal is perpendicular to the tail
             from .utilities import make_perpendicular

+ 6 - 1
readtree.py

@@ -206,7 +206,12 @@ def solve_schema_to_tree(nc, all_nc, roots=[], error_popups=False):
     prOrange(f"Expanding schema {tree.name} in node {nc} with length {length}.")
 
     solver = SchemaSolver(nc, all_nc, np, error_popups=error_popups)
-    solved_nodes = solver.solve()
+    try:
+        solved_nodes = solver.solve()
+    except Exception as e:
+    #     # the schema will run the error cleanup code, we just need to raise or not
+        if error_popups:
+            raise e
     prWhite(f"Schema declared {len(solved_nodes)} nodes.")
 
     # maybe this should be done in schema solver. TODO invesitigate a more efficient way

+ 15 - 5
schema_solve.py

@@ -67,7 +67,8 @@ class SchemaSolver:
                 # solver may be in a nested schema, and its node's signature may have
                 # uuid/index attached.
                 get_sig = (*self.node.ui_signature, ui_node.bl_idname) 
-                if not (mantis_node := self.all_nodes.get(get_sig)): raise RuntimeError(wrapRed(f"Not found: {get_sig}"))
+                if not (mantis_node := self.all_nodes.get(get_sig)):
+                    raise RuntimeError(wrapRed(f"Not found: {get_sig}"))
                 self.schema_nodes[signature] = mantis_node
                 mantis_node.fill_parameters(ui_node)
             # HACK to make Group Nodes work
@@ -233,12 +234,12 @@ class SchemaSolver:
         # this self.index_link is only used here?
         if self.index_link is None:
             # this should be impossible because the Schema gets an auto-generated Int input.
-            raise NotImplementedError("This code should be unreachable. Please report this as a bug!")
+            raise NotImplementedError(" 241 This code should be unreachable. Please report this as a bug!")
         if (self.index_link.from_node):
             connection = self.index_link.from_node.outputs[self.index_link.from_socket].connect(node=to_node, socket=ui_link.to_socket.name)
         # otherwise we can autogen an int input I guess...?
         else:
-            raise RuntimeError("I was expecting there to be an incoming connection here for Schema Length")
+            raise RuntimeError("247 I This code should be unreachable. Please report this as a bug!")
 
     def handle_link_from_incoming_connection_input(self, frame_mantis_nodes, ui_link):
         incoming = self.incoming_connections[ui_link.from_socket.name]
@@ -465,6 +466,7 @@ class SchemaSolver:
         # So we should not need to add any new dependencies unless there is a bug elsewhere.
         # and in fact, I could skip this in some cases, and should investigate if profiling reveals a slowdown here.
         forbidden=set()
+        e = None
         # forbid some nodes - they aren't necessary to solve the schema & cause problems.
         while unprepared:
             nc = unprepared.pop()
@@ -473,7 +475,7 @@ class SchemaSolver:
                     nc.bPrepare()
                 except Exception as e:
                     e = execution_error_cleanup(nc, e, show_error = self.error_popups)
-                    raise e # always raise so that we don't enter an infinite loop.
+                    break
                 if nc.node_type == 'DUMMY_SCHEMA':
                     self.solve_nested_schema(nc)
             elif nc.node_type == 'DUMMY_SCHEMA' and not self.test_is_sub_schema(nc):
@@ -491,6 +493,8 @@ class SchemaSolver:
                         unprepared.appendleft(dep)
                 if can_add_me:
                     unprepared.appendleft(nc) # just rotate them until they are ready.
+            if e: # todo: need a way to crash Schema so I don't have to raise.
+                raise e
 
     def solve_iteration(self):
         """ Solve an iteration of the schema.
@@ -711,7 +715,13 @@ class SchemaSolver:
             return {} # just don't do anything - it's OK to have a noop schema if it doesn't have dependencies.
         for index in range(self.solve_length):
             self.index = index
-            frame_mantis_nodes = self.solve_iteration()
+            try:
+                frame_mantis_nodes = self.solve_iteration()
+            except Exception as e:
+                self.node.base_tree.hash=''
+                if self.error_popups == False:
+                    raise e
+                return {}
             for sig, nc in frame_mantis_nodes.items():
                 if nc.node_type == 'DUMMY_SCHEMA':
                     self.nested_schemas[sig] = nc

+ 5 - 1
utilities.py

@@ -15,7 +15,7 @@ def prPurple(*args): print (*[wrapPurple(arg) for arg in args])
 def prWhite(*args): print (*[wrapWhite(arg) for arg in args])
 def prOrange(*args): print (*[wrapOrange(arg) for arg in args])
 
-
+from .base_definitions import FLOAT_EPSILON
 
 # add THIS to the top of a file for easy access:
 # from mantis.utilities import (prRed, prGreen, prPurple, prWhite,
@@ -661,6 +661,10 @@ def gen_nc_input_for_data(socket):
 ####################################
 
 def make_perpendicular(v1, v2):
+    if (v1.length_squared < FLOAT_EPSILON) or (v2.length_squared < FLOAT_EPSILON):
+        raise RuntimeError("Cannot generate perpendicular vetor for zero-length vector")
+    if (v2.dot(v1)==0):
+        raise RuntimeError("Failed to generate perpindicular vector.")
     projected = (v2.dot(v1) / v1.dot(v1)) * v1
     perpendicular = v2 - projected
     return perpendicular