Skip to content

Fix TypeError in lane_builder when width_end is None#24

Open
BastianHavers wants to merge 3 commits into
RI-SE:mainfrom
BastianHavers:fix/lane-builder-none-width-end
Open

Fix TypeError in lane_builder when width_end is None#24
BastianHavers wants to merge 3 commits into
RI-SE:mainfrom
BastianHavers:fix/lane-builder-none-width-end

Conversation

@BastianHavers
Copy link
Copy Markdown
Collaborator

Problem

Exporting to OpenDRIVE crashes with:

orbit.export.opendrive_writer - ERROR - Error writing OpenDrive: unsupported operand type(s) for -: 'NoneType' and 'float'

Root Cause

In lane_builder.py, the _create_lane method uses lane_obj.has_variable_width to decide whether to compute a linear width transition. However, has_variable_width returns True when any polynomial coefficient (width_b, width_c, width_d) is non-zero — even if width_end is None.

When this happens, the line:

width_b = (lane_obj.width_end - lane_obj.width) / section_length_m

attempts None - float, causing the TypeError.

This can occur during round-trip import/export of OpenDRIVE files that have non-zero polynomial width coefficients but no explicit width_end.

Fix

Changed the condition from lane_obj.has_variable_width to lane_obj.width_end is not None, which matches the safe guard already used in opendrive_writer._create_connecting_lane_element (line 1446).

When width_end is None but polynomial coefficients are set, they are now correctly preserved as-is instead of being overwritten.

Tests

  • All 110 existing tests in test_lane_builder.py and test_opendrive_writer.py pass.
  • Added missing width_end=None to mock Lane objects in tests for completeness.

BastianHavers and others added 3 commits April 1, 2026 14:36
The _create_lane method in lane_builder.py crashed with:
  TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

The condition 'lane_obj.has_variable_width' can be True when only
polynomial coefficients (width_b/c/d) are non-zero but width_end is
None. In that case, the line:
  width_b = (lane_obj.width_end - lane_obj.width) / section_length_m
attempts None - float, causing the crash.

Fix: check 'lane_obj.width_end is not None' instead, matching the
safe guard already used in opendrive_writer._create_connecting_lane_element.
When width_end is None but polynomial coefficients are set, they are
now correctly preserved as-is.

Also adds the missing width_end=None to test mocks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant