Hello,
I seem to have found an API bug in AutoCAD 2018.1 update. The code below works fine prior to update, but crashes after installing update. I've narrowed down the problem as such...
Bug explained in one sentence:
If a Dependent LayerTableRecord is initially opened ForRead, and UpgradeOpen is used before setting IsLocked or IsFrozen to True, AutoCAD will crash once the transaction is committed.
This code crashes in 2018.1
using (Transaction tr = WorkingDatabase.TransactionManager.StartTransaction()) { LayerTable lt = tr.GetObject(WorkingDatabase.LayerTableId, OpenMode.ForWrite); foreach (ObjectId LayId in lt) {
LayerTableRecord lay = tr.GetObject(LayId, OpenMode.ForRead); if (lay.IsDependent) { lay.UpgradeOpen(); lay.IsLocked = true; lay.IsFrozen = true; } } tr.Commit(); }
Where affected, I have modified my application code to ALWAYS open LayerTableRecords ForWrite. See modified code below...
This code does NOT crash in 2018.1
using (Transaction tr = WorkingDatabase.TransactionManager.StartTransaction()) { LayerTable lt = tr.GetObject(WorkingDatabase.LayerTableId, OpenMode.ForWrite); foreach (ObjectId LayId in lt) {
LayerTableRecord lay = tr.GetObject(LayId, OpenMode.ForWrite); if (lay.IsDependent) { lay.IsLocked = true; lay.IsFrozen = true; } } tr.Commit(); }
Does anyone see an issue with my code that could be the problem? If not, would be nice to have a case opened to track when the issue is fixed.
Thanks,
Jon Albert
Solved! Go to Solution.