Closed Failxxx closed 2 years ago
The problem seems to come from the fact the original draw function is not restored when the add-on is unregistered.
Thus, in __init__.py
we could add these lines:
from bpy.types import VIEW3D_HT_tool_header
from nimphs.properties.utils.others import info_header_draw
...
# Reset draw function of VIEW_3D header
global info_header_draw
VIEW3D_HT_tool_header.draw = info_header_draw
And in nimphs/properties/utils/others.py
:
# A variable where we can store the original draw function
def info_header_draw(s, c) -> None: # noqa: D103
return None
# State variable to prevent saving multiple times original VIEW_3D header draw function
global info_header_draw_saved
info_header_draw_saved = False
# Inspired by: https://blog.michelanders.nl/2017/04/how-to-add-progress-indicator-to-the-info-header-in-blender.html
def register_custom_progress_bar() -> None:
"""Register the custom progress bar."""
# Save the original draw method of Info header
global info_header_draw
global info_header_draw_saved
if not info_header_draw_saved:
info_header_draw = deepcopy(VIEW3D_HT_tool_header.draw)
info_header_draw_saved = True
# Create a new draw function
def new_info_header_draw(self, context):
global info_header_draw
# First call to the original function
info_header_draw(self, context)
# Then add the prop that acts as a progress bar
scene_prop = context.scene.get("nimphs", None)
if scene_prop is None:
return
m_op_value = context.scene.nimphs.get("m_op_value", -1)
if m_op_value >= 0.0 and m_op_value <= 100.0:
self.layout.separator()
text = context.scene.nimphs.m_op_label
self.layout.prop(context.scene.nimphs, "m_op_value", text=text, slider=True)
# Replace the draw function by our new function
# Blender crashes sometimes when using the progress bar in dev mode
if not DEV_MODE:
VIEW3D_HT_tool_header.draw = new_info_header_draw
However, this does not work because a part of the header is removed when restoring the original draw function, but comes back when the add-on is re-registered:
Short description
Blender crashes after disabling the add-on from preferences.
Current behavior
When you go in the editor preferences and disable the add-on, after closing the window, blender simply crashes.
Expected behavior
We would like Blender not to crash after disabling the add-on!
Steps to reproduce
System information
Add-on: v0.4.0 Blender: 3.0.1 Python: 3.9.12 OS: Ubuntu 22.04.1 LTS
Logs and screenshots
Crash report: