feat(io): drop parser-garbage entities at load time
acadrust's DWG reader occasionally desynchronises on certain files (observed on render.dwg: 1519 of 1763 LwPolylines arrived with non-unit normals in the 1e200+ range and 100k phantom vertices). Tessellating those entities allocates gigabytes and produces NaN-laden wires, freezing the UI. Add a pre-tessellation guard that scans freshly loaded documents and drops any entity failing a cheap sanity check: non-unit normal, non-finite or absurd coordinate, or vertex count above 100k. Count of dropped entities is threaded through DerivedCaches and surfaced as a warning in the command line so the user knows the file was patched up on the way in. Same file in DXF form parses cleanly (0 corrupt), so this is strictly a DWG-path workaround until the upstream parser bug is fixed. The new examples/inspect_polyline.rs is a one-off diagnostic that dumps LwPolyline/Polyline2D/Polyline3D fields plus a corrupt-entity count; useful for narrowing down the acadrust bug. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
586df77b2c
commit
b2588e1790
4 changed files with 270 additions and 2 deletions
|
|
@ -69,6 +69,10 @@ pub struct DerivedCaches {
|
|||
pub hatches: HashMap<Handle, HatchModel>,
|
||||
pub images: HashMap<Handle, ImageModel>,
|
||||
pub meshes: HashMap<Handle, MeshModel>,
|
||||
/// Number of entities removed by the corrupt-entity guard during load.
|
||||
/// Reported back to the UI so the user knows when a file had parser-junk
|
||||
/// entities silently dropped.
|
||||
pub corrupt_dropped: usize,
|
||||
}
|
||||
|
||||
/// Build hatch / image / mesh caches from a document without needing `&mut Scene`.
|
||||
|
|
@ -191,6 +195,7 @@ pub fn build_derived_caches(doc: &CadDocument) -> DerivedCaches {
|
|||
hatches,
|
||||
images,
|
||||
meshes,
|
||||
corrupt_dropped: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue