Access violation Error

Access violation Error

a.kouchakzadeh
Advocate Advocate
408 Views
3 Replies
Message 1 of 4

Access violation Error

a.kouchakzadeh
Advocate
Advocate

Hi, Im having trouble with my code.

Im jigging a region which I constantly hatch it by each mouse movement. its a pretty heavy process. 

 

my jig is in a loop so every time user clicks, some objects are added to database and again ed.drag(this) to start jig again immediately.

 

some users face this error message and complain AutoCAD crashes.

 

Error.png

 

this does not happen on my machine so I cant verify how or when does this happen.

I also Have a try catch block every where to narrow the exception location but no luck so far.

 

this is my code where I append entities when user clicks:

 

private void SetBlockRefXData(Transaction tr,Sprinkler sprinkler)
{
    var xDataDictionary = new Dictionary<string, string>
    {
        {"type", InputData.SprinklerType.ToString() },
        {"spacing",InputData.PendentSpacing},
        {"coverage",InputData.PendentCoverage},
        {"deftoceiling", sprinkler.IsUnderBeam.Item1 ?
            InputData.DeflectorToBeam.ToString() : InputData.DeflectorToCeiling.ToString() },
        {"IsUnderBeam",sprinkler.IsUnderBeam.Item1.ToString() },
    };
    XDataUtil.SetXdata(tr, sprinkler.BlockReference, "BeamRuleApp", xDataDictionary);
}

public void Append(Sprinkler sprinkler,JigOptionCreator jigOptions)
{
    try
    {
        var tr = _db.TransactionManager.TopTransaction;
        var ed = ACAD.DocumentManager.GetDocument(_db).Editor;
        var curSpace = tr.GetObject(_db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
        var coveredHatch = sprinkler.CoveredHatch;

        var dst = (DimStyleTable)tr.GetObject(_db.DimStyleTableId, OpenMode.ForRead, true);
        ObjectId dstId = ObjectId.Null;
        if (!dst.Has(InputData.DimStyle))
            dstId = _db.GetDimstyleData().ObjectId;
        else
            dstId = dst[InputData.DimStyle];

        if (InputData.KeepDimensions)
        {
            if (jigOptions.DimLineA != null)
            {
                curSpace.AppendEntity(jigOptions.DimLineA);
                tr.AddNewlyCreatedDBObject(jigOptions.DimLineA, true);
            }
            if (jigOptions.DimLineB != null)
            {
                curSpace.AppendEntity(jigOptions.DimLineB);
                tr.AddNewlyCreatedDBObject(jigOptions.DimLineB, true);
            }
        }
        if (InputData.MergeHatches)
        {
            var typedValue = new TypedValue[]
            {
                new TypedValue(0, "HATCH"),
                new TypedValue(8, "NSVLayout"),
            };
            var selectionFilter = new SelectionFilter(typedValue);
            var selectionResult = ed.SelectAll(selectionFilter);
            if (selectionResult.Status == PromptStatus.OK)
            {
                var previousHatchedRegions = new Region();
                foreach (ObjectId id in selectionResult.Value.GetObjectIds())
                {
                    var hatch = tr.GetObject(id, OpenMode.ForRead) as Hatch;
                    if (hatch != null)
                    {
                        var curves = hatch.GetBoundary();
                        var curveSegments = new DBObjectCollection();
                        foreach (var curve in curves)
                        {
                            curveSegments.Add(curve);
                        }
                        foreach (Region region in Region.CreateFromCurves(curveSegments))
                        {
                            previousHatchedRegions.BooleanOperation(BooleanOperationType.BoolUnite,
                                region.Clone() as Region);
                        }
                        foreach (var curve in curves)
                        {
                            curve.Dispose();
                        }
                    }
                }
                var currentCoveredRegion = sprinkler.CoveredRegion;
                currentCoveredRegion.BooleanOperation(BooleanOperationType.BoolUnite, previousHatchedRegions);

                foreach (ObjectId id in selectionResult.Value.GetObjectIds())
                {
                    var hatch = tr.GetObject(id, OpenMode.ForWrite) as Hatch;
                    if (hatch != null)
                    {
                        hatch.Erase();
                    }
                }
                coveredHatch = HatchRegion.ToColorIndex(150, 150, currentCoveredRegion);
            }
        }
        if (coveredHatch != null)
        {
            curSpace.AppendEntity(coveredHatch);
            tr.AddNewlyCreatedDBObject(coveredHatch, true);
        }
                
        curSpace.AppendEntity(sprinkler.BlockReference);
        tr.AddNewlyCreatedDBObject(sprinkler.BlockReference, true);

        SetBlockRefXData(tr, sprinkler);

        var tpv = new TypedValue[1];
        tpv.SetValue(new TypedValue((int)DxfCode.BlockName, "NSVPENDENTTEMPSPRINKLER"), 0);
        var sprinklerFilter = new SelectionFilter(tpv);
        var sset = ed.SelectAll(sprinklerFilter);

        try
        {

            if (sset.Status != PromptStatus.OK)
                return;
            DrawOrderTable dot = tr.GetObject(curSpace.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
            var objToMove = new ObjectIdCollection(sset.Value.GetObjectIds());

            if (jigOptions.DimLineA != null && jigOptions.DimLineA.ObjectId != ObjectId.Null)
                objToMove.Add(jigOptions.DimLineA.ObjectId);
            if (jigOptions.DimLineB != null && jigOptions.DimLineB.ObjectId != ObjectId.Null)
                objToMove.Add(jigOptions.DimLineB.ObjectId);

            dot.MoveToTop(objToMove);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Exception in draw order table");
            throw ex;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception in entity appender");
        throw ex;
    }
}

 

any help is much appreciated.

 

 

0 Likes
409 Views
3 Replies
Replies (3)
Message 2 of 4

kerry_w_brown
Advisor
Advisor

Are you clients using an outdated or unsupported graphics card ??

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 3 of 4

kerry_w_brown
Advisor
Advisor

or :

https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/AutoCAD-FATAL-ERRO...

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 4 of 4

a.kouchakzadeh
Advocate
Advocate

No sir.
I did come across that link and I managed to get anydesk from one of my users. I could not detect how or when the issue happens but I checked the computer ram, graphic card and cpu. every thing is new and updated.

my codes are written with .net 4.8.

does AuoCAD below 2020 support those libraries?

what I noticed is my hatch flickers with each mouse movement in 2018. but it does work. after a couple of clicks, the message popsup and AutoCAD crashes.

0 Likes