Skip to content

Commit

Permalink
fix a rendering bug for top_down mode in multi-agent envs (#468)
Browse files Browse the repository at this point in the history
I found that in multi-agent envs, if render mode is top_down, it will fail rendering on my Mac. I figure out that the `position` attribute in `TopDownRenderer` class will be initialized as None. It's ok for the `_draw` method while in single-agent env, b/c the `self.current_track_vehicle` will have a value and is not None. But in MA Envs, since there is no `self.current_track_vehicle`, it will cause a bug of None Type error.  I kind of fix it by following code in previous version of MetaDrive repo. Hope it will help!
  • Loading branch information
jimmydengpeng committed Jul 16, 2023
1 parent 2db10d3 commit 8615563
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions metadrive/obs/top_down_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,11 @@ def _draw(self, *args, **kwargs):
canvas = self._runtime_canvas
field = self._render_canvas.get_size()
if not self.target_vehicle_heading_up:
cam_pos = v.position if self.position is None else self.position
position = self._runtime_canvas.pos2pix(*cam_pos)
if self.position is not None or v is not None:
cam_pos = (self.position or v.position)
position = self._runtime_canvas.pos2pix(*cam_pos)
else:
position = (field[0] / 2, field[1] / 2)
off = (position[0] - field[0] / 2, position[1] - field[1] / 2)
self.canvas.blit(source=canvas, dest=(0, 0), area=(off[0], off[1], field[0], field[1]))
else:
Expand Down

0 comments on commit 8615563

Please sign in to comment.