Skip to content

[Bug]: SmartButton icons set via __selfinit__ do not update during reload in C# launcher #3424

Description

@Wurschdhaud

✈ Pre-Flight checks

  • I don't have SentinelOne antivirus installed (see above for the solution)
  • I have searched in the issues (open and closed) but couldn't find a similar issue
  • I have searched in the pyRevit Forum for similar issues
  • I already followed the installation troubleshooting guide thoroughly
  • I am using the latest pyRevit Version

🐞 Describe the bug

When a SmartButton's selfinit script changes the button icon using set_icon(), the icon change does not persist after a pyRevit reload. The button reverts to the icon that was parsed from disk during the initial load.

Example being the update button: after updating, the button remains orange instead of resetting.

⌨ Error/Debug Message

update button doesn't clear its orange color after updating (which triggers reloading)

♻️ To Reproduce

No response

⏲️ Expected behavior

Root Cause:

The C# loader's IconManager maintains a BitmapCache for loaded bitmap sources 1 . While the ExtensionParser clears its _iconCache during reload via ClearAllCaches() 2 , the IconManager's BitmapCache is never cleared. The ClearCache() method exists 3 but is not called in the reload sequence.

Reload Flow:

  1. ExtensionParser.ClearAllCaches() clears the icon file path cache
  2. Icons are re-parsed from disk and applied via IconManager.ApplyIcon() 4
  3. SmartButton __selfinit__ runs and may call set_icon() to override the icon 5
  4. On next reload, step 2 re-applies the cached bitmap from the BitmapCache, overriding the __selfinit__ changes

Comparison with Python Loader:

The legacy Python loader does not have this issue because it creates new bitmaps on every set_icon() call without a persistent cache 6 . The ButtonIcons class reads the file and creates bitmaps fresh each time 7 .

Suggested Fix:

Call IconManager.ClearCache() during the reload sequence to ensure bitmaps are reloaded from disk, similar to how the ExtensionParser clears its icon path cache.

Notes

The issue is specific to the C# loader path. The Python loader's icon handling in uimaker.py and ribbon.py does not use a persistent bitmap cache, so SmartButton icon changes via __selfinit__ work correctly in the legacy loader.

🖥️ Hardware and Software Setup (please complete the following information)

latest

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions