Page MenuHome

[2.77a - 2.78] Removal of custom icon previews during add-on unregister crashes Blender
Closed, ResolvedPublic

Description

System Information
Linux Mint 18, GTX 660 Ti

Blender Version
Broken: 2.77a.abf6f08; 2.78.4bb1e22

Short description of error
If any custom icon is currently visible in Blender window, then Blender crashes while add-on is being unregistred.

Exact steps for others to reproduce the error

  1. Install add-on from "previews_bug.zip" by copying "previews_addon.py" and "icons" folder to "scripts/addons" folder
  2. Once installed enable addon "Previews Example" in User Preferences
  3. In 3D View open Tool Shelf and select "Previews" tab. You should see 10 buttons with custom icons (all look the same
  4. Now open up User Preferences again and rapidly enable and disable this addon. Blender will crash soon.

ZIP file:

  • previews_bug.zip:

Event Timeline

Simon (notallowed) updated the task description. (Show Details)
Simon (notallowed) updated the task description. (Show Details)
Bastien Montagne (mont29) lowered the priority of this task from 90 to 50.

Confirmed, think problem comes from deferred loading of previews from files…

Happy to see I finally made proper bug report, which can be reproduced.

Btw I am also experiencing another problem with previews. That icons get randomly lost after some time (they simply don't show in UI anymore), is it possible to be tided to this or?

hi, the addon here should be in it's own folder, not a single file with an icons folder dropped into blenders file structure.
my_folder/__init__.py /icons is the right structure.
for the correct way to use icons please see mesh_tinycad addon, I'm unable to reproduce this crash with mesh_tinycad
try this & let us know if it still crashes

@Brendon Murphy (meta-androcto) afaict, your comparison is wrong, mesh-tiny-cad does not have any 'static' panel always visible, showing custom icons right? it’s only in 'Special' W menu?

Issue here is when you unregister an addon (i.e. remove its custom icons) while those custom icons are being lazily loaded by UI code (because this loading happens in a thread iirc, which means it can be using custom icons data while it’s being cleaned out), at least that what I’m guessing until I investigate properly the issue. ;)

@Bastien Montagne (mont29)
tested the file & was able to reproduce only if I pressed reg/unreg the addon multiple times as fast as I could. pressing reg/unreg multiple times at a reasonable rate, say 0.5 second gap, the crash does not occur. I think what happens here is the Button Mashing is too quick for the addon to reload the custom icons.

I tested some other panel addons that use custom icons with no conclusion yet.

I just wonder is Button Mashing the reg/unreg of an addon usual use & expected use. ;)

@Brendon Murphy (meta-androcto) it depends on add-on and on how much and many custom icons are used and visible at the time of reg/unreg. I have add-on which has around 20 custom icons usages in tool shelf so I get to crash with that add-on quicker usually after 1-2 reg/unreg presses.

@Simon (notallowed) hi, sorry to be on your case here seemingly ;)
currently there is a delay when loading custom icons on first load.
I enable your test addon (in it's own folder using __init__.py), when I click the tab to open the panel the icons incrementally load. You can see it, they load one after the other taking maybe 1 second to populate the menu. From here they are loaded & switching tabs does not incur the "lag".
I'm thinking that the reg/unreg really quick beats this time, so blender tries to grab the icons & in the middle tries to grab them again, causing the crash.
This is prevented by taking your time & not pushing the current limitations,
I can easily reproduce this crash & also easily not crash here by not smashing the reg/unreg button.

Also I noticed in wazou's speedflow addon, which also has custom icons within a toolshelf panel, this is handled somewhat better. It has an option in addons preferences to display the custom icon panel. When addons preferences are saved as "use panel" the panel is on by default when you start blender, however if you reg/unreg the addon, the panel is not displayed until you re-activate it in the addons preferences.

To summarize, whilst there is an issue & a crash here, it's preventable.
i feel here the crash is some what forced by the user.
It's not usual behavior to enable/disable the same addon in fast succession. Don't do that ;)
The method used by wazou, whilst I tested, I did not examine the code, that said, it's impossible to reproduce this crash, using his code.

Simon (notallowed) added a comment.EditedOct 27 2016, 1:02 PM

@Brendon Murphy (meta-androcto) Yep I know to that if I will slowly enable/disable addon that crash won't happen, but that's not really a solution :)
Well I myself went aroound this the way:
I am not removing previews at all on unregister (they are kept in module dictionary variable for reuse) and if user again enables add-on preview is still accessible and rather than creating whole previews again I just reload images. The only downside is that preview collection is never cleared until you close Blender, but shouldn't be noticeable problem for user.

Another solution popped up during writing this post, that on each register I could create new preview collection and once new collection is created and used by UI I can in peace delete old collection hopefully without a crash.

However I still think that this "bug" should be take care of at some point ;)