[BUG] crash on Arch material if two materials with the same material name are created

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

[BUG] crash on Arch material if two materials with the same material name are created

Post by bernd »

Just run the following code ... bang ... crash

Code: Select all

doc = App.newDocument("MyDoc")
import Arch
matobj1 = Arch.makeMaterial("MyObjectName1")
matobj1.Material = {"Name": "MyMaterialName", "DiffuseColor": "(0.0, 1.0, 0.0, 0)"}
matobj2 = Arch.makeMaterial("MyObjectName2")
matobj2.Material = {"Name": "MyMaterialName", "DiffuseColor": "(0.0, 1.0, 1.0, 0)"}


OS: Debian GNU/Linux 10 (buster) (KDE//usr/share/xsessions/plasma)
Word size of FreeCAD: 64-bit
Version: 0.20.26232 (Git)
Build type: Unknown
Branch: master
Hash: cd8ce95f53d4bf95d906912d8a93665b47cd592f
Python version: 3.7.3
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Switzerland (de_CH)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: crash on Arch material if two materials with the same material name are created by Python

Post by bernd »

The crash only happens if in Preferences the following is deactivated:
General --> Document --> Allow duplicate object labels in one document
User avatar
Roy_043
Veteran
Posts: 8537
Joined: Thu Dec 27, 2018 12:28 pm

Re: crash on Arch material if two materials with the same material name are created by Python

Post by Roy_043 »

No problem here:

Code: Select all

OS: Windows 8.1 (6.3)
Word size of FreeCAD: 64-bit
Version: 0.20.26201 (Git)
Build type: Release
Branch: master
Hash: 9f2dd4a363053e87e1b1def0d005ed441d378796
Python version: 3.8.12
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: Dutch/Netherlands (nl_NL)
Attachments
material-test.FCStd
(4.26 KiB) Downloaded 31 times
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: crash on Arch material if two materials with the same material name are created by Python

Post by bernd »

are you sure you deactivated the preference? See my second post.
User avatar
Roy_043
Veteran
Posts: 8537
Joined: Thu Dec 27, 2018 12:28 pm

Re: crash on Arch material if two materials with the same material name are created by Python

Post by Roy_043 »

Yes. Just check my file. The 2nd material has not received the "MyMaterialName" name.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: crash on Arch material if two materials with the same material name are created by Python

Post by bernd »

That is the problem why you get no crash. Did you run the Python code to create this file?

another file attached.

- open the file
- double click on MyMaterialName1
- The Arch Material task panel opens
- delete the "1" in Name ("MyMaterialName")
- click ok

- if duplicate labels are allowed in prefs it works if not crash ...


material-test_2.FCStd
(4.43 KiB) Downloaded 29 times
User avatar
Roy_043
Veteran
Posts: 8537
Joined: Thu Dec 27, 2018 12:28 pm

Re: crash on Arch material if two materials with the same material name are created by Python

Post by Roy_043 »

bernd wrote: Thu Oct 28, 2021 10:05 am That is the problem why you get no crash. Did you run the Python code to create this file?
Yes.

bernd wrote: Thu Oct 28, 2021 10:05 am - if duplicate labels are allowed in prefs it works if not crash ...
Confirmed.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: crash on Arch material if two materials with the same material name are created by Python

Post by bernd »

Does it mean it crashs for you with my provided file and workflow but not with the Python code?

If yes ... Strange ... Would you try the Python code once again :oops: ?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: crash on Arch material if two materials with the same material name are created by Python

Post by bernd »

The problem is the onChanged method of the ArchMaterial.

it takes the Name from the Material dictionary and sets it to the object label, than FreeCAD changes the object label because they should not be equal, thus onChanged is called and sets again the object label. This results in an Endlesloop.

To be honest I do not like the idea to make FreeCAD reset object labels. Even if the user changes the label the label is reset. I do not know any other object ATM who does this.

bernd
User avatar
Roy_043
Veteran
Posts: 8537
Joined: Thu Dec 27, 2018 12:28 pm

Re: crash on Arch material if two materials with the same material name are created

Post by Roy_043 »

Regarding the code: I now understand the confusion.

If I run the code by pasting it in the Python console there is no problem. But running the code with Std_DlgMacroExecuteDirect does produce a crash.
Post Reply