When iterating across segs in a subsector, always make sure the seg is not a glseg before you access its linedef.
Test files: