Skip to content

ArgumentOutOfRangeException with large coordinates (CGCS2000/Gauss-Krüger projection) #6

@colapy93

Description

@colapy93

Bug Report: ArgumentOutOfRangeException when viewing CAD files with large coordinates (CGCS2000)

Description

When attempting to preview DWG/DXF files using the CGCS2000 coordinate system (China Geodetic Coordinate System 2000), the plugin throws an ArgumentOutOfRangeException. This coordinate system uses large projection coordinates (e.g., X ≈ 3,000,000+ meters), which appears to cause overflow in the CADImport.dll rendering pipeline.

Error Message

System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at CADImport.SGLines.□(CADCollection1, CADCollection1)
at CADImport.CADPolyLine.□(DPoint)
at CADImport.CADPolyLine.□(DPoint)
at CADImport.CADPainter1.□(CADPolyLine)
at CADImport.CADPainter1.□(Object)
at CADImport.CADPainter1.(CADEntity)
at CADImport.CADPainter1.DrawEntity(CADEntity Ent)
at CADImport.CADEntity.□(CADConverter, CADEntityProc, CADEntityProc)
at CADImport.CADGroup.Iterate(CADConverter AConverter, CADEntityProc convProc, CADEntityProc finishProc)
at CADImport.CADPainter1.DrawEnt(String aVal)
at CADImport.CADPainter1.□(CADImage, DRect)

Environment

  • OS: Windows 10/11
  • QuickLook Version: Latest
  • Plugin Version: Latest (downloaded from releases)
  • CAD File Coordinate System: CGCS2000 / Gauss-Krüger projection (3° zone)
  • Typical Coordinate Values: X ≈ 3,000,000 ~ 4,000,000 meters, Y ≈ 200,000 ~ 600,000 meters

Steps to Reproduce

  1. Create or obtain a DWG file with CGCS2000 coordinates (large values like X=39500000, Y=2500000)
  2. Select the file in Windows Explorer
  3. Press Space to trigger QuickLook preview
  4. Error dialog appears immediately

Expected Behavior

The plugin should normalize or handle large coordinates internally, or at least catch the exception gracefully instead of crashing.

Actual Behavior

Hard crash with ArgumentOutOfRangeException in SGLines.

Additional Context

I attempted to modify the source code to normalize coordinates (subtracting the mean offset to bring coordinates near origin), but discovered that CADImport.dll is a closed-source commercial library. The API properties (StartPoint, Center, Entities, etc.) used by Roo Code-generated code do not match the actual DLL API, making it impossible to fix without the proper API documentation.

Suggested Fix

Consider adding coordinate normalization in the CADImage loading phase:

  1. Calculate bounding box center after loading
  2. Translate all entities by (-centerX, -centerY, -centerZ)
  3. Store the offset for potential restoration if needed
  4. This would prevent the overflow in the rendering pipeline

Alternatively, catch the ArgumentOutOfRangeException in DrawEntity and display a user-friendly message suggesting the user move the drawing closer to the origin (0,0).

Thank you for maintaining this plugin! It would be great if it could support surveying/engineering coordinates used in China and other regions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions