OpenNaja / cobra-tools

A suite of GUI tools for extracting and modifying OVL and OVS archives, as well as editing the associated in-house file formats. Also includes a model plugin for Blender. For downloads, guides, and FAQs visit:
https://opennaja.github.io/cobra-tools/
GNU General Public License v3.0
94 stars 27 forks source link

`_get_attribute_list` cannot load modules in `name_type_map` listed after it #349

Closed svip closed 12 months ago

svip commented 12 months ago

Describe the bug Using https://github.com/Candoran2/nifxml for formats/nif, using this guide, I end up with an addon Blender cannot load:

  File "[...]/generated/formats/nif/__init__.py", line 1, in <module>
    from generated.formats.nif.imports import name_type_map
  File "[...]/generated/formats/nif/imports.py", line 883, in <module>
    class_object.init_attributes()
  File "[...]/generated/base_struct.py", line 263, in init_attributes
    cls._attribute_list = tuple(cls._get_attribute_list())
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[...]/generated/formats/nif/nilegacy/niobjects/NiParticleModifier.py", line 29, in _get_attribute_list
    yield 'controller', name_type_map['Ptr'], (0, name_type_map['NiParticleSystemController']), (False, None), (lambda context: context.version >= 50528269, None)
                                                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'NiParticleSystemController'

To Reproduce Steps to reproduce the behavior:

  1. Follow the guide listed above.
  2. Attempt to install the addon in Blender.

Expected behavior That it would install without problem.

Version Info:

This bug honestly baffles me, because looking at the Python code, it should be correct:

name_type_map = {}
for type_name, module in type_module_name_map.items():
    name_type_map[type_name] = getattr(import_module(module), type_name)
for class_object in name_type_map.values():
    if callable(getattr(class_object, 'init_attributes', None)):
        class_object.init_attributes()

My formats/nif/imports.py contain this as the bottom (like all other imports.py). name_type_map should already be filled in by the time init_attributes() is called, and yet somehow it appears that it isn't?

I was thinking of posting this issue at https://github.com/Candoran2/nifxml, but that project does not appear to allow issues. But I can see @Candoran2 is involved both places.

Candoran2 commented 12 months ago

Which branch of the xml were you using?

svip commented 12 months ago

I'm using develop on nifxml.

Candoran2 commented 12 months ago

Hm, odd. You're right that name_type_map should already be filled in by the time init_attributes is called. You could try manually adding a try: except case around the failing piece of code and then see what's in the name_type_map at the time of the exception.

svip commented 12 months ago

Oh dear. I feel kind of guilty for bringing this up, but clearly it was some internal cache in Blender. I cannot believe I did not at least attempt restarting Blender. I will just close this issue. It's just that Blender gives a clear implication that it can unload and reload addons at any time.

HENDRIX-ZT2 commented 12 months ago

It's just that Blender gives a clear implication that it can unload and reload addons at any time.

That's very risky. I always restart hehe