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
- Create or obtain a DWG file with CGCS2000 coordinates (large values like X=39500000, Y=2500000)
- Select the file in Windows Explorer
- Press Space to trigger QuickLook preview
- 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:
- Calculate bounding box center after loading
- Translate all entities by (-centerX, -centerY, -centerZ)
- Store the offset for potential restoration if needed
- 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.
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
Steps to Reproduce
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:
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.