Robert-N7 / abmatt

ANoob's Brres Material Tool for Mario Kart Wii
GNU General Public License v3.0
14 stars 3 forks source link

'bool' object has no attribute 'all' #69

Closed Heath123 closed 3 years ago

Heath123 commented 3 years ago
Exception has occurred: AttributeError
'bool' object has no attribute 'all'
  File "/home/heath/Downloads/abmatt/abmatt/converters/colors.py", line 143, in combine
    if (self.rgba_colors != color.rgba_colors).all():
  File "/home/heath/Downloads/abmatt/abmatt/converters/geometry.py", line 59, in combine
    self.colors.combine(geometry.colors, True)
  File "/home/heath/Downloads/abmatt/abmatt/converters/convert_dae.py", line 173, in __add_geometry
    if not geo[0].combine(geometry):
  File "/home/heath/Downloads/abmatt/abmatt/converters/convert_dae.py", line 198, in __parse_nodes
    self.__add_geometry(x, material_geometry_map)
  File "/home/heath/Downloads/abmatt/abmatt/converters/convert_dae.py", line 37, in load_model
    self.__parse_nodes(dae.get_scene(), material_geometry_map, matrix)
  File "/home/heath/Downloads/abmatt/abmatt/command.py", line 837, in run_convert
    mdl = converter.load_model(model)
  File "/home/heath/Downloads/abmatt/abmatt/command.py", line 769, in run_cmd
    return self.run_convert()
  File "/home/heath/Downloads/abmatt/abmatt/command.py", line 705, in run_commands
    cmd.run_cmd()
  File "/home/heath/Downloads/abmatt/abmatt/load_config.py", line 358, in parse_args
    if not Command.run_commands(cmds):
  File "/home/heath/Downloads/abmatt/abmatt/__main__.py", line 22, in main
    files = load_config.parse_args(argv, base_path)
  File "/home/heath/Downloads/abmatt/abmatt/__main__.py", line 29, in <module>
    main()

(this is using VS Code so the stacktrace is backwards from usual)

Heath123 commented 3 years ago

https://stackoverflow.com/a/59345651/4012708 So it seems this is only valid for numpy arrays but rgba_colors is a normal Python list

Heath123 commented 3 years ago

Also even if they were numpy arrays wouldn't this make it only return True if none of the elements are equal?

Heath123 commented 3 years ago
Python 3.9.6 (default, Jul  3 2021, 16:40:50) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> b = np.array([1, 1, 1])
>>> c = (a == b)
>>> c
array([ True, False, False])
>>> c.all()
False
>>> 

Because this checks if all of them are True when you want to check if all of them are False (so if not (self.rgba_colors == color.rgba_colors).all(): would work in that case)

Heath123 commented 3 years ago

Well the fix is wrong but now I can't reproduce the bug and I didn't attach an example file...

Heath123 commented 3 years ago

Never mind, reproduced it model.zip

Robert-N7 commented 3 years ago

I believe the desired behavior is to check if the two are equal. Because it may be either ndarray or a list, the best fix would be to check the length of the outside dimensions and use a for loop to compare each element if the lengths are equal.

Heath123 commented 3 years ago

Oh, they are both Numpy arrays, but comparing them can return a single boolean sometimes for some reason

Heath123 commented 3 years ago

@Robert-N7 My first thought was wrong, I assumed it was a list but it isn't

Heath123 commented 3 years ago

I narrowed down the problem at https://replit.com/@HeathMitchell1/nparray

Heath123 commented 3 years ago

Looks like the correct fix is to use https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html

https://stackoverflow.com/a/63030288/4012708

Heath123 commented 3 years ago

Made a new PR: #71