[Bug] Creating Material with the same name crashes FreeCAD

A forum to discuss the implementation of a good Materials system in FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

[Bug] Creating Material with the same name crashes FreeCAD

Post by vanuan »

Steps to reproduce:
1. Create a material with name "Material"
2. Create another material under the same name ("Material")

Expected behavior:

An error says "A material with such name already exists"
.
Actual behavior:

Code: Select all

Traceback (most recent call last):
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 299, in onChanged
    if not self.isSameColor(obj.Color,c):
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 286, in isSameColor
    if round(c1[0],r) == round(c2[0],r):
<class 'RecursionError'>: maximum recursion depth exceeded while calling a Python object
Fatal Python error: Cannot recover from stack overflow.

Current thread 0x00007f28349ca800 (most recent call first):
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 286 in isSameColor
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 299 in onChanged
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 321 in onChanged
  File "/workspace/build/Mod/Arch/ArchMaterial.py", line 362 in onChanged
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by bernd »

which FC version? Where do you create the material? Since there are arch errors I assume you create a arch material.
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by vanuan »

bernd wrote: Fri Aug 21, 2020 7:34 pm which FC version? Where do you create the material? Since there are arch errors I assume you create a arch material.
Yes, Arch material. Are there other materials? This was on master branch. Also tested in App image.

When you create a material, there's a name prompt. If you enter the same name it will crash.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by bernd »

vanuan wrote: Tue Aug 25, 2020 12:28 pm
bernd wrote: Fri Aug 21, 2020 7:34 pm which FC version? Where do you create the material? Since there are arch errors I assume you create a arch material.
Yes, Arch material. Are there other materials? This was on master branch. Also tested in App image.

When you create a material, there's a name prompt. If you enter the same name it will crash.
In FEM you can add a material too. Arch and FEM material are based on the same object (inheritance), and they use the same material files for storage of material properties, but eventually they are different FreeCAD objectcs (different module and class and command) and thus also in the tree.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by bernd »

- start FreeCAD
- change to Arch
- new document
- click on material button
- in task panel do not change anything click ok. The new material will be named Material
- click on material button once again
- in task panel do not change anything click ok. The new material will be named Material
- I get no error

Code: Select all

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22209 (Git)
Build type: Release
Branch: master
Hash: 9c3f9b72a82249d5fcf1f543dd69a78740251b26
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Switzerland (de_CH)
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by Syres »

bernd wrote: Thu Aug 27, 2020 12:41 pm - in task panel do not change anything click ok. The new material will be named Material
- click on material button once again
- in task panel do not change anything click ok. The new material will be named Material
Nope for me the second material is called Material001 and I can confirm the OP that if you use the same name again, FreeCAD crashes rather than gracefully producing an error such as 'You cannot use the same name twice, please change the name and try again'.

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22284 (Git)
Build type: Release
Branch: master
Hash: bf1e8e48389f5e9e25bd77b67fe98da4213e797c
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by Kunda1 »

Syres wrote: Thu Aug 27, 2020 12:59 pm Nope for me the second material is called Material001 and I can confirm the OP that if you use the same name again, FreeCAD crashes rather than gracefully producing an error such as 'You cannot use the same name twice, please change the name and try again'.
I can confirm the same as @Syres
I get Material001 and manually need to remove the 001 and press Ok to get FC to crash. Here is the output:

Code: Select all

$ ./FreeCAD_0.19-22284-Linux-Conda_glibc2.12-x86_64.AppImage 
FreeCAD 0.19, Libs: 0.19R22284 (Git)
<snip>

Traceback (most recent call last):
  File "/tmp/.mount_FreeCAaFURo4/usr/lib/python3.8/site-packages/freecad/asm3/mover.py", line 482, in slotChangedObject
    Assembly.checkPartChange(obj,prop)
  File "/tmp/.mount_FreeCAaFURo4/usr/lib/python3.8/site-packages/freecad/asm3/assembly.py", line 3558, in checkPartChange
    if not cls.canAutoSolve() or prop in _IgnoredProperties:
  File "/tmp/.mount_FreeCAaFURo4/usr/lib/python3.8/site-packages/freecad/asm3/assembly.py", line 3538, in canAutoSolve
    from . import solver
  File "<frozen importlib._bootstrap>", line 393, in parent
<class 'RecursionError'>: maximum recursion depth exceeded while calling a Python object
Fatal Python error: Cannot recover from stack overflow.
Python runtime state: initialized

Current thread 0x00007fea10fc2280 (most recent call first):
  File "<frozen importlib._bootstrap>", line 393 in parent
  File "/tmp/.mount_FreeCAaFURo4/usr/lib/python3.8/site-packages/freecad/asm3/assembly.py", line 3538 in canAutoSolve
  File "/tmp/.mount_FreeCAaFURo4/usr/lib/python3.8/site-packages/freecad/asm3/assembly.py", line 3558 in checkPartChange
  File "/tmp/.mount_FreeCAaFURo4/usr/lib/python3.8/site-packages/freecad/asm3/mover.py", line 482 in slotChangedObject
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 321 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  File "/tmp/.mount_FreeCAaFURo4/usr/Mod/Arch/ArchMaterial.py", line 362 in onChanged
  ...
/tmp/.mount_FreeCAaFURo4/AppRun: line 41:  9650 Aborted                 (core dumped) ${MAIN} "$@"
OS: Manjaro Linux (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22284 (Git) AppImage
Build type: Release
Branch: master
Hash: bf1e8e48389f5e9e25bd77b67fe98da4213e797c
Python version: 3.8.5
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by wmayer »

That's an Arch specific bug of the class _ArchMaterial. As you can see from the error logs FreeCAD crashes because of a stack overflow. This happens because the function onChanged() is called in an infinite recursion.

Inside onChanged() it's checked whether the name of the material and the label matches. If not, the name will be overridden with the label which modifies the local material instance (the variable d).

At the end of the function d is assigned to the object's material property which of course re-invokes onChanged(). This doesn't cause a problem because the modified material has the new name and thus the material won't be re-assigned.

However, somewhere there is a weird logic (I couldn't figure out where) is that at some point the old material with the wrong name is restored and this way it tries to update the label with the wrong name. The system (i.e. PropertyString::setValue) doesn't set this value and instead assigns Material001 which again invokes the onChanged() method.

So, the whole thing is a ping pong game by an alternating assignment of material and label.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by Syres »

The quick and dirty workaround I've come up with is https://github.com/FreeCAD/FreeCAD/comp ... 16:patch-3
vince-ice
Posts: 1
Joined: Sat Oct 10, 2020 5:45 pm

Re: [Bug] Creating Material with the same name crashes FreeCAD

Post by vince-ice »

Syres wrote: Fri Aug 28, 2020 10:33 am The quick and dirty workaround I've come up with is https://github.com/FreeCAD/FreeCAD/comp ... 16:patch-3
This works for me
Post Reply