Page MenuHome

You can't register a `GizmoGroup` after unregistering it
Closed, ResolvedPublic

Description

System Information
Operating system: windows 64bits

Blender Version
Broken:
blender2.8, 2019-02-10

Short description of error
When trying to unregister and then register an addon that supports GizmoGroups. An error message is displayed and the process stops.

Exact steps for others to reproduce the error
In the gizmo_simple.py template, add these lines:

issubclass(MyLightWidgetGroup, bpy.types.GizmoGroup)

bpy.utils.unregister_class(MyLightWidgetGroup)
bpy.utils.register_class(MyLightWidgetGroup)

When trying to execute the code through Blender, you should see the error message :

Traceback (most recent call last):
  File "\gizmo_simple.py", line 52, in <module>

TypeError: expected GizmoGroup subclass of class "MyLightWidgetGroup"
Error: Python script fail, look in the console for now...

Event Timeline

Jacques Lucke (JacquesLucke) triaged this task as Confirmed, Medium priority.

It's interesting that this error is related to issubclass(MyLightWidgetGroup, bpy.types.GizmoGroup). When I remove this line, it works just fine.

Here is a solution I did to avoid this error.
But it looks kind of hacky.

diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 32e8fe40c6a..f105c2980f8 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -646,6 +646,12 @@ class Gizmo(StructRNA):
         return (batch, shader)
 
 
+# Dummy class to keep the reference in `bpy_types_dict` and avoid
+# erros like: "TypeError: expected GizmoGroup subclass of class ..."
+class GizmoGroup(StructRNA):
+    __slots__ = ()
+
+
 # Only defined so operators members can be used by accessing self.order
 # with doc generation 'self.properties.bl_rna.properties' can fail
 class Operator(StructRNA, metaclass=RNAMeta):

(It would be nice if it could be fixed soon)

This should be fine to commit, even if it's a bit of a workaround it shouldn't harm to have it here like other classes.