Poly-Haven / polyhavenassets

A Blender add-on to integrate our assets natively in the asset browser
GNU General Public License v3.0
312 stars 21 forks source link

Error print when running Blender in the background (cli) #118

Closed venomgfx closed 3 months ago

venomgfx commented 3 months ago

Describe the bug When running Blender through the command line, the Poly Haven add-on prints errors. It's harmless as in it doesn't stop the rest of Blender from working, but it pollutes the terminal which isn't nice.

I believe it is just missing a check if Blender is being run in the background or not before starting to look into anything window manager related.

Console log

Exception in thread Thread-1 (check_for_new_assets):
Traceback (most recent call last):
    context.window_manager.pha_props.new_assets = 0
  File "C:\blender\4.3\python\Lib\threading.py", line 1045, in _bootstrap_inner
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WindowManager' object has no attribute 'pha_props'
    self.run()
  File "C:\blender\4.3\python\Lib\threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\user\AppData\Roaming\Blender Foundation\Blender\4.3\scripts\addons\polyhavenassets\utils\check_for_new_assets.py", line 17, in check_for_new_assets
    context.window_manager.pha_props.new_assets = 0
    ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\blender\4.3\scripts\modules\bpy_restrict_state.py", line 24, in window_manager
    return self._real_data.window_managers[0]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: bpy_prop_collection[index]: index 0 out of range, size 0

Blender quit

To Reproduce

  1. Run Blender from the command line.
  2. See error

Expected behavior No errors.

Additional context Tested in Blender 4.3 which is alpha at the moment, but the add-on works just fine through the UI.