morse-simulator / morse

The Modular OpenRobots Simulation Engine
http://morse-simulator.github.io/
Other
350 stars 155 forks source link

Fixed and simplified create_new_material() #787

Closed cehberlin closed 5 years ago

cehberlin commented 6 years ago

Fixed a problem that occured with some blender environments, the actual reason is unclear.

However, the included simplification of the create_new_material() method solved the problem.

The original problem stack trace was the following:

Exception ignored in: <bound method Environment.del of <morse.builder.environment.Environment object at 0x7f94cce4a908>> Traceback (most recent call last): File "/usr/local/lib/python3/dist-packages/morse/builder/environment.py", line 831, in del self.create() File "/usr/local/lib/python3/dist-packages/morse/builder/environment.py", line 300, in create component.after_renaming() File "/usr/local/lib/python3/dist-packages/morse/builder/sensors.py", line 290, in after_renaming self.create_laser_arc() File "/usr/local/lib/python3/dist-packages/morse/builder/sensors.py", line 283, in create_laser_arc arc.active_material = self.get_ray_material() File "/usr/local/lib/python3/dist-packages/morse/builder/sensors.py", line 186, in get_ray_material ray_material = bpymorse.create_new_material() File "/usr/local/lib/python3/dist-packages/morse/builder/bpymorse.py", line 96, in create_new_material material_name = [name for name in get_materials().keys() \ IndexError: pop from empty list

nicolaje commented 6 years ago

Thanks. I woul like to test that before it is merged, as I have had bad experience with Blender not necessarily putting newly created stuff at the end of a list (see PR #760 )

cehberlin commented 6 years ago

@nicolaje Did you check this? For me this is still an issue with some environment without my fix.

PierrickKoch commented 6 years ago

how about :

def create_new_material():
    all_materials = get_materials().keys()
    new_material()
    material_name = [name for name in get_materials().keys() \
                     if name not in all_materials]
    if material_name:
        return get_material(material_name[0])
    else:  # see #787
        return get_materials()[-1]
cehberlin commented 5 years ago

@pierriko Good idea! I just tested it with a problematic blender environment and it works fine! Would be awesome if this could be merged!

nicolaje commented 5 years ago

What about:

def create_new_material():
    all_materials_before = set(get_materials())
    new_material()
    return (all_materials_before ^ set(get_materials())).pop()
cehberlin commented 5 years ago

Hi guys, would be nice if after this was solved could also be merged to master! Thanks, Chris

severin-lemaignan commented 5 years ago

Merged!