Page 1 of 2

[Bug] Creating Material with the same name crashes FreeCAD

Posted: Fri Aug 07, 2020 1:33 am
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

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

Posted: Fri Aug 21, 2020 7:34 pm
by bernd
which FC version? Where do you create the material? Since there are arch errors I assume you create a arch material.

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

Posted: Tue Aug 25, 2020 12:28 pm
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.

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

Posted: Wed Aug 26, 2020 10:42 am
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.

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

Posted: Thu Aug 27, 2020 12:41 pm
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)

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

Posted: Thu Aug 27, 2020 12:59 pm
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)

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

Posted: Thu Aug 27, 2020 2:41 pm
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)

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

Posted: Thu Aug 27, 2020 5:26 pm
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.

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

Posted: Fri Aug 28, 2020 10:33 am
by Syres
The quick and dirty workaround I've come up with is https://github.com/FreeCAD/FreeCAD/comp ... 16:patch-3

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

Posted: Mon Oct 12, 2020 10:50 am
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