View Issue Details

IDProjectCategoryView StatusLast Update
0002322FreeCADBugpublic2016-01-19 02:06
Reporterlanciaux Assigned Toyorik  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionno change required 
Fixed in Version0.16 
Summary0002322: Crash in updating/opening files in Assembly2 workbench due to recent changes in FreeCAD function open() after commit 969b43b
DescriptionAssembly2 workbench is not working at once you do a second import or do any update of an assembly of at least 2 components

in function "importpart" of importpart.py

 if filename.lower().endswith('.fcstd'):
    => this fails ! doc = FreeCAD.open(filename)

* Abort *** an exception was raised, but no catch was found.
... The exception is:SIGSEGV 'segmentation violation' detected. Address ...
Additional InformationIt appears after FreeCAD commit "969b43b"
TagsNo tags attached.
FreeCAD Information

Activities

yorik

2015-11-01 13:42

administrator   ~0006514

The assembly2 workbench is not part of FreeCAD, it's an independent project, and it has its own issues tracker. Please report this bug on the assembly2 project itself: https://github.com/hamish2014/FreeCAD_assembly2/issues
Thanks!

lanciaux

2015-11-01 14:46

reporter   ~0006515

It has already been notified on Assembly2 workbench git bug tracker. We do not have understood differences made starting 969b43b on FreeCAD github.

I and others will stop updating FreeCAD until it got fixed.

Yours

Ludovic (Belgium)

yorik

2015-11-01 15:01

administrator   ~0006516

I'm absolutely sorry to hear that, but it doesn't change our position. That commit extends the App.setActiveDocument/App.getDocument function to allow it to receive a python document object instead of a string. It doesn't change anything else, AFAICS. This change seems valid to me, I don t see any reason why it should not exist, and it is apparently working without problems.

Unless you can show me there is a bug in freecad, and not in assembly2, I don t see anything we need to do here...

hamish2014

2015-11-02 07:57

reporter   ~0006517

Last edited: 2015-11-02 07:59

Ludovic, thanks for creating the bug report.

Yorik, thanks for your response.
Furthermore, a big thanks to you and the FreeCAD team for the excellent work you do!

I agree that you are not responsible for patching assembly 2.
The assembly 2 issue is logged at
https://github.com/hamish2014/FreeCAD_assembly2/issues/59
The reasons Ludovic and I suspect the this is a bug in FreeCAD and not assembly 2 are:

1) the crash occurs in Assembly2 code. importPart.py. which was last altered on the 10th of September, one Month before the crashes began occurring, and

2) conducted tests show the crashes began after the changes in FreeCAD described in
https://github.com/FreeCAD/FreeCAD/commit/969b43bb64b5241ede622a6872b59cabce346fa6

That said, the code in assembly2/importPart.py could have been using the FreeCAD openDocument and closeDocument in a manner they were never intended to be used...

Anyway to replicate the crash, open FreeCAD and run the following from the FreeCAD console

def importPart( filename ):
    currentDoc = FreeCAD.ActiveDocument.Name
    FreeCAD.Console.PrintMessage("opening %s\n" % filename)
    doc = FreeCAD.openDocument(filename)
    FreeCAD.Console.PrintMessage("successfully opened\n")
    FreeCAD.setActiveDocument(currentDoc) #comment out to stop crashing ...
    # copy data from doc
    FreeCAD.closeDocument(doc.Name)

importPart('/tmp/a.fcstd') # freecad file containing a cube
importPart('/tmp/b.fcstd') # freecad file containing a cylinder


In FreeCAD 0.16, Libs: 0.16R5667 (Git) this does not cause a crash ..

hamish2014

2015-11-02 08:25

reporter   ~0006519

Update, rewrote assembly2.importPart.py to work around issue.
So non-urgent ...

yorik

2015-11-02 15:47

administrator   ~0006520

Thanks for the additional info hamish

However, executing your example code above doesn't crash for me...
If there is no active document opened when running the function, it stops at the first line, obviously. If there is one, the function can be ran any number of times without crashing.

I don't know how is your assembly2 code, but I would suggest making this kind of function stronger, by always testing if there is an active document before doing things with it, etc.

hamish2014

2015-11-02 17:26

reporter   ~0006521

Verbose steps to reproduce crash on Linux system:

Launch FreeCAD from Bash, and then paste the following into the Python console

App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")

App.getDocument("Unnamed").saveAs("/tmp/a.fcstd")
App.getDocument("Unnamed").saveAs("/tmp/b.fcstd")

App.closeDocument("Unnamed")
App.setActiveDocument("")
App.ActiveDocument=None
Gui.ActiveDocument=None

App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")


def importPart( filename ):
    currentDoc = FreeCAD.ActiveDocument.Name
    FreeCAD.Console.PrintMessage("opening %s\n" % filename)
    doc = FreeCAD.openDocument(filename)
    FreeCAD.Console.PrintMessage("successfully opened\n")
    FreeCAD.setActiveDocument(currentDoc) #comment out to stop crashing ...
    # copy data from doc
    FreeCAD.closeDocument(doc.Name)

importPart('/tmp/a.fcstd')
importPart('/tmp/b.fcstd')

lanciaux

2015-11-11 20:01

reporter   ~0006538

I wanted to apologize a bit my words since Hamish has managed to fix the way he was importing files to accomodate changes to FreeCAD code. I now have updated sources to most recent modifications as workbench assembly2 is fully running again.

yorik

2015-12-02 13:21

administrator   ~0006573

Ah I see where the problem lies, hamish. Indeed your last code above causes a crash.

When opening a new document, if there is an empty document opened already, it gets closed automatically. This happens in your function, and therefore, when trying to set the active document, currentDoc refers to a document name that doesn't exist anymore.

Normally this gives an error, but not a crash:

App.newDocument("somename")
App.closeDocument("somename")
App.setActiveDocument("somename")

Maybe there is some race condition occurring in your function... Not easy to debug in any case. Probably better to always test that a document name exists before, for ex. with App.listDocuments()

yorik

2016-01-03 19:03

administrator   ~0006662

I think this can be closed? Or is there anything you think should be done here hamish?

hamish2014

2016-01-04 06:55

reporter   ~0006665

Hi Yorik, I am happy. You are welcome to close the issue.

yorik

2016-01-04 11:11

administrator   ~0006667

A good bug is a closed bug :)

Issue History

Date Modified Username Field Change
2015-11-01 09:42 lanciaux New Issue
2015-11-01 13:42 yorik Note Added: 0006514
2015-11-01 13:42 yorik Status new => closed
2015-11-01 13:42 yorik Assigned To => yorik
2015-11-01 13:42 yorik Resolution open => no change required
2015-11-01 14:46 lanciaux Note Added: 0006515
2015-11-01 14:46 lanciaux Status closed => feedback
2015-11-01 14:46 lanciaux Resolution no change required => reopened
2015-11-01 15:01 yorik Note Added: 0006516
2015-11-02 07:57 hamish2014 Note Added: 0006517
2015-11-02 07:59 hamish2014 Note Edited: 0006517
2015-11-02 08:25 hamish2014 Note Added: 0006519
2015-11-02 15:47 yorik Note Added: 0006520
2015-11-02 17:26 hamish2014 Note Added: 0006521
2015-11-11 20:01 lanciaux Note Added: 0006538
2015-11-11 20:01 lanciaux Status feedback => assigned
2015-12-02 13:21 yorik Note Added: 0006573
2016-01-03 19:03 yorik Note Added: 0006662
2016-01-03 19:03 yorik Status assigned => feedback
2016-01-04 06:55 hamish2014 Note Added: 0006665
2016-01-04 11:11 yorik Note Added: 0006667
2016-01-04 11:12 yorik Status feedback => closed
2016-01-04 11:12 yorik Resolution reopened => no change required
2016-01-19 02:06 yorik Fixed in Version => 0.16