Scripting: Blender should be able to handle unknown icon exceptions
So when you have an add-on that uses an internal Blender icon, if Blender decides to change that icon name (for whatever reason) between versions, that completely breaks your add-on. It kills that section of UI code. In some cases it even crashes Blender.
Instead, if it can't find the icon, it should just default to a 'NONE' icon or something similar, and then it should log and print an error so the developer is alerted to the problem. It shouldn't just obliterate the UI code with a runtime error. It should be able to handle that exception neatly.
4 Comments
I can build Blender now. I have a partial implementation for this that seems to work for registration. Will work on layout drawing next. The file I did it in is actually bpy_rna.cc
I've narrowed this down to 2 possible files where this would possibly be done:
projects.blender.org/blender/blender/src/commit/9e920bc95ba1ad8ea091d0c1bcd356a138082441/source/blender/editors/interface/interface_layout.cc
or
projects.blender.org/blender/blender/src/commit/9e920bc95ba1ad8ea091d0c1bcd356a138082441/source/blender/editors/interface/interface_icons.cc
Or maybe it's neither, not sure.
So instead of this:
TypeError: UILayout.prop(): error with keyword argument "icon" - enum "GPBRUSH_ERASE_STROKE" not found in ('NONE', 'BLANK1', 'AUTOMERGE_OFF', 'AUTOMERGE_ON', 'CHECKBOX_DEHLT', 'CHECKBOX_HLT',...
It should be something like:
Unknown Icon: Icon "GPBRUSH_ERASE_STROKE" could not be found. Replaced with default "NONE" icon.
And I'm posting this here because the only alternative is to fix this on my end with a find_icon() function, since I'm tired of the Blender gods breaking my add-on just because they want to change an icon name willy nilly. Which is fine, obviously, but Blender should be able to handle these cases without runtime errors that kill add-on UI's.