File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,8 +108,23 @@ export class Path {
108108 * @returns BufferGeometry representing the path
109109 */
110110 geometry ( opts : { extrusionWidthOverride ?: number ; lineHeightOverride ?: number } = { } ) : BufferGeometry {
111- if ( this . _vertices . length < 3 ) {
112- return new BufferGeometry ( ) ;
111+ if ( this . _vertices . length < 6 ) {
112+ // a path needs at least 2 points to be valid
113+ console . warn ( 'Path has less than 6 points, returning empty geometry' ) ;
114+ return null ;
115+ }
116+
117+ // check for zero length paths
118+ // do this check for each segment
119+ for ( let i = 0 ; i < this . _vertices . length - 3 ; i += 3 ) {
120+ const dx = this . _vertices [ i ] - this . _vertices [ i + 3 ] ;
121+ const dy = this . _vertices [ i + 1 ] - this . _vertices [ i + 4 ] ;
122+ const dz = this . _vertices [ i + 2 ] - this . _vertices [ i + 5 ] ;
123+ const distance = Math . sqrt ( dx * dx + dy * dy + dz * dz ) ;
124+ if ( distance < 0.0001 ) {
125+ console . warn ( 'Path has zero length, skipping' ) ;
126+ return null ;
127+ }
113128 }
114129
115130 return new ExtrusionGeometry (
Original file line number Diff line number Diff line change @@ -867,6 +867,9 @@ export class WebGLPreview {
867867 extrusionWidthOverride : this . extrusionWidth ,
868868 lineHeightOverride : this . lineHeight
869869 } ) ;
870+
871+ if ( ! geometry ) return ;
872+
870873 this . disposables . push ( geometry ) ;
871874 geometries . push ( geometry ) ;
872875 } ) ;
You can’t perform that action at this time.
0 commit comments