Get polyline entities crash from BlockReference in release mode

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I am using the realdwg sdk, i found a problem with getting polyline entities inside a new BlockReference
So if it's the block from the model space, it's like this
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord blockrecord = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
Then i can iterate all the entities to get the polyline like this
void getPolyline(BlockTableRecord bt, Transaction tr) {
foreach (ObjectId id in bt)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
if (ent is Polyline) {
getDATA((Polyline)ent)
}
if (ent is BlockReference) {
//recursive calling
getPolyline((BlockReference)ent, tr)
}
}
}
void getDATA(Polyline p) {
for (int i = 0; i < p.NumberOfVertices; i++)
{
SegmentType t = p.GetSegmentType(i);
Console.WriteLine(t);
if (t == SegmentType.Line)
{
LineSegment2d l = p.GetLineSegment2dAt(i);
//Save to my own data structure
}
else if (t == SegmentType.Arc)
{
CircularArc2d arc = p.GetArcSegment2dAt(i);
//Save to my another data structure
}
}
}
The problem is that if the ent is another BlockReference; I get crash error.
Should I start a new Transaction for each new BlockReference?
If I just get the Polyline of first the BlockReference(The model space one), not calling the recursive function, it works fine without crash. If I call the recursive part. I can the error:
System.AccessViolationException was unhandled
Source=Acdbmgd
StackTrace:
Autodesk.AutoCAD.DatabaseServices.Transaction.DeleteUnmanagedObject()
Autodesk.AutoCAD.Runtime.DisposableWrapper.!DisposableWrapper()
Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose(Boolean A_0)
Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose()
What did I do wrong?
Thx