Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

_get_attribute_list cannot load modules in name_type_map listed after it #349

Closed
svip opened this issue Aug 4, 2023 · 5 comments
Closed

Comments

@svip
Copy link

svip commented Aug 4, 2023

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:

  • Python Version: 3.11.4
  • Blender Version: 3.5
  • Cobra Tools Version: master from today (4 August 2023) (8533e47)

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
Copy link
Contributor

Which branch of the xml were you using?

@svip
Copy link
Author

svip commented Aug 4, 2023

I'm using develop on nifxml.

@Candoran2
Copy link
Contributor

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
Copy link
Author

svip commented Aug 4, 2023

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.

@svip svip closed this as completed Aug 4, 2023
@HENDRIX-ZT2
Copy link
Contributor

HENDRIX-ZT2 commented Aug 4, 2023

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants