浏览代码

Fix Infinite Execution in I/O (Again)

Joseph Brandenburg 6 月之前
父节点
当前提交
524c910491
共有 2 个文件被更改,包括 19 次插入6 次删除
  1. 6 2
      __init__.py
  2. 13 4
      i_o.py

+ 6 - 2
__init__.py

@@ -209,8 +209,10 @@ def update_handler(scene):
         trees = [p.node_tree for p in context.space_data.path]
         if not trees: return
         if (node_tree := trees[0]).bl_idname in ['MantisTree']:
+            if node_tree.is_exporting:
+                return 
             if node_tree.prevent_next_exec : pass
-            elif node_tree.do_live_update and not (node_tree.is_executing or node_tree.is_exporting):
+            elif node_tree.do_live_update and not (node_tree.is_executing):
                 prev_links = node_tree.num_links
                 node_tree.num_links = len(node_tree.links)
                 if (prev_links == -1):
@@ -231,8 +233,10 @@ def execute_handler(scene):
         trees = [p.node_tree for p in context.space_data.path]
         if not trees: return
         if (node_tree := trees[0]).bl_idname in ['MantisTree']:
+            if node_tree.is_exporting:
+                return 
             if node_tree.prevent_next_exec : node_tree.prevent_next_exec = False
-            elif node_tree.tree_valid and node_tree.do_live_update and not (node_tree.is_executing or node_tree.is_exporting):
+            elif node_tree.tree_valid and node_tree.do_live_update and not (node_tree.is_executing):
                 scene.render.use_lock_interface = True
                 node_tree.execute_tree(context)
                 scene.render.use_lock_interface = False

+ 13 - 4
i_o.py

@@ -402,8 +402,6 @@ def export_to_json(trees, path="", write_file=True, only_selected=False):
     # I'm gonna do this in a totally naive way, because this should already be sorted properly
     #   for the sake of dependency satisfaction. So the current "tree" should be the "main" tree
     tree.filepath = path
-
-    return {'FINISHED'}
     
 
 def do_import_from_file(filepath, context):
@@ -412,6 +410,7 @@ def do_import_from_file(filepath, context):
     all_trees = [n_tree for n_tree in bpy.data.node_groups if n_tree.bl_idname in ["MantisTree", "SchemaTree"]]
 
     for tree in all_trees:
+        tree.is_exporting = True
         tree.do_live_update = False
 
     with open(filepath, 'r', encoding='utf-8') as f:
@@ -430,7 +429,9 @@ def do_import_from_file(filepath, context):
     # otherwise:
     # repeat this because we left the with, this is bad and ugly but I don't care
     for tree in all_trees:
+        tree.is_exporting = False
         tree.do_live_update = True
+        tree.prevent_next_exec = True
     return {'CANCELLED'}
 
 def do_import(data, context):
@@ -808,7 +809,11 @@ class MantisExportNodeTreeSaveAs(Operator, ExportHelper):
         prGreen("Exporting node graph with dependencies...")
         for t in trees:
             prGreen ("Node graph: \"%s\"" % (t.name))
-        return export_to_json(trees, self.filepath)
+        base_tree.is_exporting = True
+        export_to_json(trees, self.filepath)
+        base_tree.is_exporting = False
+        base_tree.prevent_next_exec = True
+        return {'FINISHED'}
 
 # Save
 class MantisExportNodeTreeSave(Operator):
@@ -828,7 +833,11 @@ class MantisExportNodeTreeSave(Operator):
         prGreen("Exporting node graph with dependencies...")
         for t in trees:
             prGreen ("Node graph: \"%s\"" % (t.name))
-        return export_to_json(trees, base_tree.filepath)
+        base_tree.is_exporting = True
+        export_to_json(trees, self.filepath)
+        base_tree.is_exporting = False
+        base_tree.prevent_next_exec = True
+        return {'FINISHED'}
 
 # Save Choose:
 class MantisExportNodeTree(Operator):