Ticket #4233 - Access violation and file corruption after undo duplicate sketch

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Waldschrat
Posts: 10
Joined: Tue Dec 24, 2019 5:58 am

Ticket #4233 - Access violation and file corruption after undo duplicate sketch

Post by Waldschrat »

This is the discussion topic for issue #4233

Duplicating and then undoing causes, I guess, internal memory corruption, leading to access violations on subsequent operations and unusable corrupted file on save.

Steps to reproduce:
- Open file attached to the bug report. (Or just create a cube by padding a sketch.)
- Go to Part Design workbench.
- Select top face of cube.
- Create new sketch attached to selected face.
- Draw something, maybe a circle around the coordinate center.
- Close sketch.
- Select sketch in tree view.
- Click Edit --> Duplicate selected object.
- Click Yes.
- Click Edit --> Undo
- Click Edit --> Duplicate selected object.
- Click No.
- Observe "Exception - Access violation"
- Click OK twice.
- Save file.
- Close and reopen FreeCAD.
- Open recently saved file.
- Observe a totally unusable file.

FreeCAD infos:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
Last edited by Kunda1 on Tue Dec 24, 2019 3:28 pm, edited 2 times in total.
Reason: Added ticket number to thread title
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Access violation and file corruption after undo duplicate sketch

Post by chrisb »

Please retry with current 0.19. Follow next time the bug report guidelines and discuss the issue before creating a bug report.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Waldschrat
Posts: 10
Joined: Tue Dec 24, 2019 5:58 am

Re: Access violation and file corruption after undo duplicate sketch

Post by Waldschrat »

I tried to run 0.19_pre3_19036: https://github.com/FreeCAD/FreeCAD/rele ... nVS2015.7z
Downloading, unpacking and running as per instructions here: https://github.com/FreeCAD/FreeCAD/rele ... g/0.19_pre

But it fails during startup complaining about missing VCRUNTIME140_1.dll

I guess I have to install something before (some visual studio redistributable, I guess) or use a different file maybe. Any tips?
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Access violation and file corruption after undo duplicate sketch

Post by wmayer »

I can confirm the crash with v0.18 but not with v0.19. See also the ticket for further details.

The document is already corrupted after the undo and when using the Dependency graph utility it crashes when it tries to create the graph. So, very likely it's caused by a dangling pointer.

If you look at the undo history before undoing the last action you will realize that the duplication created two actions:
  1. Duplicate
  2. Duplicate a PartDesign object
When searching for this term in the source code you will find this function: https://github.com/FreeCAD/FreeCAD/blob ... y.cpp#L639
So, this function is a special re-implementation of the duplication function of the core system but does some extra PartDesign handling.
If you look at its implementation then it does:
  • Opens a transaction
  • Invokes the duplication function of the core system which also opens and commits a transaction
  • Modifies the the document
This however is a convoluted logic and creates a big mess because when opening a transaction while another one is opened the latter will be closed automatically. So, the consequence is that the invocation of the core duplication function closes the Duplicate a PartDesign object transaction and its own transaction. When the duplication function returns to its calling instance there is no pending transaction any more and further changes are not logged by a transaction.
This means parts of the operation are logged by a transaction and other parts aren't.

A workaround for now is to switch to any other workbench to make sure only the core duplication function is used. Then the document won't have inconsistencies and undo doesn't break its internal structure.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Access violation and file corruption after undo duplicate sketch

Post by wmayer »

I guess I have to install something before (some visual studio redistributable, I guess) or use a different file maybe. Any tips?
You need the redistributable for VS2015 and x64.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Access violation and file corruption after undo duplicate sketch

Post by wmayer »

Fixed with: https://github.com/FreeCAD/FreeCAD/comm ... 79dfa630cb
Note: To get the same state as before duplicating objects you must press undo twice.
Waldschrat
Posts: 10
Joined: Tue Dec 24, 2019 5:58 am

Re: Access violation and file corruption after undo duplicate sketch

Post by Waldschrat »

Ah, nice, thanks, mightily quick work, that.

Classic, I guess. Call with unexpected side effect.

I think I'll stop fighting VS and test it when the next release comes out.
Post Reply