Fix KeyError for traffic vehicles missing render_vehicle config#10
Open
BridgerB wants to merge 1 commit intocommaai:minimalfrom
Open
Fix KeyError for traffic vehicles missing render_vehicle config#10BridgerB wants to merge 1 commit intocommaai:minimalfrom
BridgerB wants to merge 1 commit intocommaai:minimalfrom
Conversation
Access self.config instead of the vehicle_config parameter directly, since traffic vehicles don't have render_vehicle in their passed config.
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
When
traffic_density > 0, spawning traffic vehicles fails with:at
metadrive/component/vehicle/base_vehicle.pyline 142.Root Cause
In
BaseVehicle.__init__, line 142 accesses the passedvehicle_configparameter directly:However, the config merging happens just before this:
BaseObject.__init__(..., self.engine.global_config["vehicle_config"])- initializesself._configwith the global vehicle_config (which includesrender_vehicle=True)self.update_config(vehicle_config)- merges the passed config intoself._configFor the main agent vehicle, the passed
vehicle_configincludesrender_vehicle, so it works. But for traffic vehicles, the passed config only contains spawn info fromtraffic_vehicle_config(spawn_lane_index, spawn_longitude, etc.) - it doesn't includerender_vehicle.After the merge,
self.config["render_vehicle"]correctly containsTrueinherited from the base config, butvehicle_config["render_vehicle"]fails because the key was never in the passed parameter.Fix
Use
self.config["render_vehicle"]instead ofvehicle_config["render_vehicle"], consistent with howuse_special_coloris accessed on line 140.