Explorar o código

fix 'struct rna of ExportGodot removed' error (#393)

* fix 'struct rna of ExportGodot removed' error if upexpected error occured while exporting

* Update __init__.py

* Update __init__.py

* Update __init__.py

Co-authored-by: U-TTE\celpec <[email protected]>
Celpec %!s(int64=4) %!d(string=hai) anos
pai
achega
aba3cfaf3f
Modificáronse 2 ficheiros con 6 adicións e 5 borrados
  1. 6 1
      io_scene_godot/__init__.py
  2. 0 4
      io_scene_godot/export_godot.py

+ 6 - 1
io_scene_godot/__init__.py

@@ -19,6 +19,7 @@ without significant importing (it's the same as Godot's tscn format).
 #
 # ##### END GPL LICENSE BLOCK #####
 
+import logging
 import bpy
 from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
 from bpy_extras.io_utils import ExportHelper
@@ -206,6 +207,7 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
 
     def execute(self, context):
         """Begin the export"""
+        exporter_log_handler = export_godot.ExporterLogHandler(self)
         try:
             if not self.filepath:
                 raise Exception("filepath not set")
@@ -218,11 +220,14 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
                 "filter_glob",
                 "xna_validate",
             ))
-
+            logging.getLogger().addHandler(exporter_log_handler)
             return export_godot.save(self, context, **keywords)
         except ValidationError as error:
             self.report({'ERROR'}, str(error))
             return {'CANCELLED'}
+        finally:
+            if exporter_log_handler:
+                logging.getLogger().removeHandler(exporter_log_handler)
 
 
 def menu_func(self, context):

+ 0 - 4
io_scene_godot/export_godot.py

@@ -313,8 +313,6 @@ class GodotExporter:
 
 def save(operator, context, filepath="", **kwargs):
     """Begin the export"""
-    exporter_log_handler = ExporterLogHandler(operator)
-    logging.getLogger().addHandler(exporter_log_handler)
 
     object_types = kwargs["object_types"]
     # GEOMETRY isn't an object type so replace it with all valid geometry based
@@ -326,6 +324,4 @@ def save(operator, context, filepath="", **kwargs):
     with GodotExporter(filepath, kwargs, operator) as exp:
         exp.export()
 
-    logging.getLogger().removeHandler(exporter_log_handler)
-
     return {"FINISHED"}