Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

StackOverFlowException on exploding blocks #465

Closed
Asura336 opened this issue Jul 11, 2023 · 1 comment
Closed

StackOverFlowException on exploding blocks #465

Asura336 opened this issue Jul 11, 2023 · 1 comment
Labels

Comments

@Asura336
Copy link

A StackOverFlowException will be thrown when exploding a Block in ModelSpace (at version 2.4.2 and 3.0.0), exception message like:

   at netDxf.XData.Clone()
   at netDxf.Tables.ApplicationRegistry.Clone(System.String)
   at netDxf.XData.Clone()
   at netDxf.Tables.ApplicationRegistry.Clone(System.String)
   at netDxf.XData.Clone()
   at netDxf.Tables.ApplicationRegistry.Clone(System.String)
   at netDxf.XData.Clone()
   at netDxf.Entities.Line.Clone()
   at netDxf.Entities.Insert.Explode()
   at Program.<Main>$(System.String[])

There is the sample code and dxf file that will raise exception.
block-stackoverflow-case.zip

using netDxf;
using netDxf.Entities;
using System.Text;

if (args.Length != 0)
{
    string src = args[0]; // dxf file path from args
    if (File.Exists(src) && src.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase))
    {
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        DxfDocument doc = DxfDocument.Load(src)
            ?? throw new NullReferenceException();

        string activeLayout = doc.Entities.ActiveLayout;
        var associatedBlock = doc.Layouts[activeLayout].AssociatedBlock;
        var docEntities = associatedBlock.Entities;
        
        List<EntityObject> entities = new List<EntityObject>();
        int count = docEntities.Count;
        for (int i = 0; i < count; i++)
        {
            var item = docEntities[i];
            switch (item)
            {
                case Insert insert:
                    entities.AddRange(insert.Explode());  // here
                    break;
                default:
                    // other...
                    entities.Add(item);
                    break;
            }
        }
        //...
    }
}
@haplokuon
Copy link
Owner

I have uploaded a fix for this problem. This problem appears when cloning the extended data associated to an application registry with circular references, the code ended in an infinite loop and in a StackOverFlow exception. This is a very uncommon case that I have never seen before, if you use AutoCad it seems that it was created by some short of plugin for it, all the application registries that had this problem started with the prefix GENIUS.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants