[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!
User avatar
DeepSOIC
Posts: 6840
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

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

Postby DeepSOIC » Sat Jan 23, 2016 12:26 am

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
Site Admin
Posts: 14588
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Sat Jan 23, 2016 11:57 am

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: 597
Joined: Tue Jan 29, 2013 10:35 pm

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

Postby eivindkvedalen » Sat Jan 23, 2016 3:02 pm

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: 597
Joined: Tue Jan 29, 2013 10:35 pm

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

Postby eivindkvedalen » Sun Jan 24, 2016 12:18 am

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
Posts: 6840
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

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

Postby DeepSOIC » Sun Jan 24, 2016 1:15 am

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

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

Postby wmayer » Sun Jan 24, 2016 9:43 am

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
Site Admin
Posts: 14588
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Tue Jan 26, 2016 10:56 am

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
Site Admin
Posts: 14588
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Tue Jan 26, 2016 11:18 am