Fix TypeError in lane_builder when width_end is None#24
Open
BastianHavers wants to merge 3 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Exporting to OpenDRIVE crashes with:
Root Cause
In
lane_builder.py, the_create_lanemethod useslane_obj.has_variable_widthto decide whether to compute a linear width transition. However,has_variable_widthreturnsTruewhen any polynomial coefficient (width_b,width_c,width_d) is non-zero — even ifwidth_endisNone.When this happens, the line:
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_widthtolane_obj.width_end is not None, which matches the safe guard already used inopendrive_writer._create_connecting_lane_element(line 1446).When
width_endisNonebut polynomial coefficients are set, they are now correctly preserved as-is instead of being overwritten.Tests
test_lane_builder.pyandtest_opendrive_writer.pypass.width_end=Noneto mock Lane objects in tests for completeness.