mrven / Blender-Asset-Creation-Toolset

Many Tools for Game Asset Creation (Import/Export FBXs, Origin Aligment Tool, Renaming, Low-Poly Art workflow tools, etc.)
GNU General Public License v3.0
299 stars 24 forks source link

Exception on unregistering in windows #4

Closed 64blit closed 9 months ago

64blit commented 2 years ago

Thanks for this awesome tool, just wanted to share this small bug I've seen on windows with blender versions 2.9 - 3.1

Not sure proper procedure for bug reporting, let me know if this is alright. Thanks again :-)

Exception in module unregister(): 'C:\\Users\\edmun\\AppData\\Roaming\\Blender Foundation\\Blender\\3.1\\scripts\\addons\\Asset_Creation_Toolset_3_1_5_290\\__init__.py'
Traceback (most recent call last):
  File "C:\Program Files (x86)\Steam\steamapps\common\Blender\3.1\scripts\modules\addon_utils.py", line 439, in disable
    mod.unregister()
  File "C:\Users\edmun\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Asset_Creation_Toolset_3_1_5_290\__init__.py", line 41, in unregister
    sys.modules[current_module_name].unregister()
  File "C:\Users\edmun\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Asset_Creation_Toolset_3_1_5_290\material_tools.py", line 802, in unregister
    bpy.types.CYCLES_PT_context_material.remove(Material_Menu_Panel)
AttributeError: 'module' object has no attribute 'CYCLES_PT_context_material'
mrven commented 1 year ago

Do you have enabled Cycles Render Plugin? This required for some functions of ACT. Image

ericwomer commented 11 months ago

I get the same error, and the Cycles Renderer Plugin comes enabled by default in Blender. I am using Blender 3.6.5.

I think it has to do with in what order the Cycles addon is unregistered, as if you enable the Cycles addon after ACT it complains about no 'CYCLES_PT_context_material' since it doesn't exist yet, and if you enable the ACT after the Cycles addon (which is the default) it complains because 'CYCLES_PT_context_material' no longer exists. I don't know if you can do a test in the modules register (this one would cause issues as ACT would have the proper modles registered.) and unregister methods to see if 'CYCLES_PT_context_material' exitsts and just bypass its unregistering or if that would add a lot of overhead.

ericwomer commented 11 months ago

The best thing I think you can do is handle the error gracefully.

Save the git repo patch to a location on your disk then test with patch -u -b --dry-run --verbose Asset_Creation_Toolset_2023_1_Bl361/material_tools.py -i path/to/where/you/saved/the.patch

Then apply with patch -u -b --verbose Asset_Creation_Toolset_2023_1_Bl361/material_tools.py -i path/to/where/you/saved/the.patch

Patch for git repo

From 48d99f8d10637b498c815a5e17ebd7b14f3bdb73 Mon Sep 17 00:00:00 2001
From: EWomer <ewomer@hotmail.com>
Date: Sat, 28 Oct 2023 21:48:44 -0400
Subject: [PATCH] Handle Cycles addon unregistering gracefully

---
 .../material_tools.py                               | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/Asset_Creation_Toolset_2023_1_Bl361/material_tools.py b/Asset_Creation_Toolset_2023_1_Bl361/material_tools.py
index 3185090..59546f1 100644
--- a/Asset_Creation_Toolset_2023_1_Bl361/material_tools.py
+++ b/Asset_Creation_Toolset_2023_1_Bl361/material_tools.py
@@ -1043,8 +1043,15 @@ def register():

 def unregister():
-       bpy.types.CYCLES_PT_context_material.remove(Material_Menu_Panel)
-       bpy.types.EEVEE_MATERIAL_PT_context_material.remove(Material_Menu_Panel)
+       try:
+               bpy.types.CYCLES_PT_context_material.remove(Material_Menu_Panel)
+       except AttributeError as err:
+               print(err)
+       try:
+               bpy.types.EEVEE_MATERIAL_PT_context_material.remove(Material_Menu_Panel)
+       except AttributeError as err:
+               print(err)

        for cls in reversed(classes):
-               bpy.utils.unregister_class(cls)
\ No newline at end of file
+               bpy.utils.unregister_class(cls)
+
-- 
2.39.2

For the non git repo patch file

Save the non git repo patch to a location on your disk then test with patch -u -b --dry-run --verbose material_tools.py -i path/to/where/you/saved/the.patch

Then apply with patch -u -b --verbose material_tools.py -i path/to/where/you/saved/the.patch

Patch for downloaded addon

diff --git a/material_tools.py b/material_tools.py
index 3185090..59546f1 100644
--- a/material_tools.py
+++ b/material_tools.py
@@ -1043,8 +1043,15 @@ def register():

 def unregister():
-       bpy.types.CYCLES_PT_context_material.remove(Material_Menu_Panel)
-       bpy.types.EEVEE_MATERIAL_PT_context_material.remove(Material_Menu_Panel)
+       try:
+               bpy.types.CYCLES_PT_context_material.remove(Material_Menu_Panel)
+       except AttributeError as err:
+               print(err)
+       try:
+               bpy.types.EEVEE_MATERIAL_PT_context_material.remove(Material_Menu_Panel)
+       except AttributeError as err:
+               print(err)

        for cls in reversed(classes):
-               bpy.utils.unregister_class(cls)
+               bpy.utils.unregister_class(cls)
+
mrven commented 9 months ago

@ericwomer Thank You for solution! Added in 8405ca21bf0801c213ca92b82f7688a8825c1b71