    }
  }
  
  static void update_line_data(const UIState *s, const cereal::ModelDataV2::XYZTData::Reader &line,
                               float y_off, float z_off, line_vertices_data *pvd, float max_distance) {
    const auto line_x = line.getX(), line_y = line.getY(), line_z = line.getZ();
    int max_idx = -1;
    vertex_data *v = &pvd->v[0];
    for (int i = 0; ((i < TRAJECTORY_SIZE) and (line_x[i] < fmax(MIN_DRAW_DISTANCE, max_distance))); i++) {
      v += calib_frame_to_full_frame(s, line_x[i], line_y[i] - y_off, line_z[i] + z_off, v);
 
</s> remove   int max_idx = -1;
 </s> add  </s> remove   for (int i = 0; ((i < TRAJECTORY_SIZE) and (line_x[i] < fmax(MIN_DRAW_DISTANCE, max_distance))); i++) {
 </s> add   for (int i = 0; i <= max_idx; i++) { </s> remove   const float max_distance = fmin(model.getPosition().getX()[TRAJECTORY_SIZE - 1], MAX_DRAW_DISTANCE);
 </s> add   auto model_position = model.getPosition();
  const float max_distance = std::clamp(model_position.getX()[TRAJECTORY_SIZE - 1],
                                        MIN_DRAW_DISTANCE, MAX_DRAW_DISTANCE);

  int max_idx = get_path_length_idx(model_position, max_distance); </s> remove     update_line_data(s, road_edges[i], 0.025, 0, &scene.road_edge_vertices[i], max_distance);
 </s> add     update_line_data(s, road_edges[i], 0.025, 0, &scene.road_edge_vertices[i], max_idx); </s> remove     max_idx = i;
 </s> add 
                             float y_off, float z_off, line_vertices_data *pvd, int max_idx) {
    }
  }
  
  static void update_line_data(const UIState *s, const cereal::ModelDataV2::XYZTData::Reader &line,
                             float y_off, float z_off, line_vertices_data *pvd, int max_idx) {
    const auto line_x = line.getX(), line_y = line.getY(), line_z = line.getZ();
    int max_idx = -1;
    vertex_data *v = &pvd->v[0];
    for (int i = 0; ((i < TRAJECTORY_SIZE) and (line_x[i] < fmax(MIN_DRAW_DISTANCE, max_distance))); i++) {
      v += calib_frame_to_full_frame(s, line_x[i], line_y[i] - y_off, line_z[i] + z_off, v);
keep keep keep keep replace keep keep keep keep keep
 ui/update_line_data: use max_idx as paramater instead of max_distance (#20256) 
selfdrive/ui/ui.cc