[Fixed] Expressions: crash when object.Name == "Placement"

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

[Fixed] Expressions: crash when object.Name == "Placement"

Post by DeepSOIC »

Hi!
The bug was narrowed down from a crash in Lattice wb reported by @Dim, here: viewtopic.php?f=3&t=13906&start=10
1. new document.
2. run:

Code: Select all

o = App.ActiveDocument.addObject("Part::FeaturePython","Placement")
3. Select the new feature. FreeCAD hits an assert, then crashes.

Note: on Windows, it crashes only in debug build. Release build seems to swallow the problem, not sure why.

OS: Windows 8.1
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6207 (Git)
Build type: Debug
Branch: (detached from abdullah/hyperbola_2016)
Hash: f80e07e04cc09cef611768a11fdbb7799460e336
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.7.1
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by wmayer »

The assert is triggered in

Code: Select all

void ExpressionBinding::bind(const App::ObjectIdentifier &_path)
{
    const Property * prop = _path.getProperty();

    Q_ASSERT(prop != 0);

    path = prop->canonicalPath(_path);
    
    //connect to be informed about changes
    DocumentObject * docObj = path.getDocumentObject();
    connection = docObj->ExpressionEngine.expressionChanged.connect(boost::bind(&ExpressionBinding::expressionChange, this, _1));
}
FYI, in a release build an assert is always a NOP (no operation).
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by eivindkvedalen »

wmayer wrote:The assert is triggered in

Code: Select all

void ExpressionBinding::bind(const App::ObjectIdentifier &_path)
{
    const Property * prop = _path.getProperty();

    Q_ASSERT(prop != 0);

    path = prop->canonicalPath(_path);
    
    //connect to be informed about changes
    DocumentObject * docObj = path.getDocumentObject();
    connection = docObj->ExpressionEngine.expressionChanged.connect(boost::bind(&ExpressionBinding::expressionChange, this, _1));
}
FYI, in a release build an assert is always a NOP (no operation).
But then we should have an immediate crash below, because prop is 0. Anyway, the issue is another case where the property is not resolved properly. I think I should be able to fix this during the weekend.

Eivind
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by eivindkvedalen »

DeepSOIC wrote:Hi!
The bug was narrowed down from a crash in Lattice wb reported by @Dim, here: viewtopic.php?f=3&t=13906&start=10
1. new document.
2. run:

Code: Select all

o = App.ActiveDocument.addObject("Part::FeaturePython","Placement")
3. Select the new feature. FreeCAD hits an assert, then crashes.
Please try https://github.com/eivindkv/free-cad-co ... ns_fixes_8

Eivind
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by DeepSOIC »

Not surprisingly, Lattice Placement doesn't crash FreeCAD anymore! Thanks Eivind!!
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by wmayer »

But then we should have an immediate crash below, because prop is 0. Anyway, the issue is another case where the property is not resolved properly. I think I should be able to fix this during the weekend.
The funny thing is that when I comment out the assert it crashes in Debug build but according to DeepSOIC not in Release mode (I haven't tested it actually). However, in the past I read somewhere that it's allowed to invoke a method also of a null pointer or dangling pointer as long as you don't access any member variables inside this method. But I am not sure if this also applies to virtual methods.
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by wmayer »

Note: on Windows, it crashes only in debug build. Release build seems to swallow the problem, not sure why.
FYI, it crashes for me immediately in Release mode.
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [bug] Expressions: crash when object.Name == "Placement"

Post by wmayer »

Post Reply