carla-simulator / carla

Open-source simulator for autonomous driving research.
http://carla.org
MIT License
10.66k stars 3.42k forks source link

destroying actors from a list #7653

Closed 00Dan00 closed 3 days ago

00Dan00 commented 2 weeks ago

CARLA version: 0.9.15 Platform/OS: Windows Problem you have experienced: I'm spawning actors that run on autopilot. When spawning I add the corresponding actor to a list to later destroy that actor. But once I call the destroy method the simulation & my kernel crashes and I get no error message. What you expected to happen: The corresponding (or all) actors to be destroyed (removed from the simulation) and the simulation still running Steps to reproduce: From my notebook. Everything works fine and my cars get spawned but once I run the last cell with the vehicle.destroy() method everything crashes.

``

import carla import random import time

client = carla.Client('localhost', 2000) client.set_timeout(5.0) world = client.get_world() spawn_points = world.get_map().get_spawn_points() spawnedcars = [] for in range(60): car_blueprint = random.choice(world.get_blueprint_library().filter("vehicle")) if car_blueprint.has_attribute('color'): color = random.choice(car_blueprint.get_attribute('color').recommended_values) car_blueprint.set_attribute('color', color) car_blueprint.set_attribute('role_name', 'autopilot')

for _ in range(5):
    try:
        spawn_point = random.choice(spawn_points)
        car_actor = world.spawn_actor(car_blueprint, spawn_point)
        car_actor.set_autopilot()
        break
    except:
        time.sleep(0.1)
        continue
spawned_cars.append(car_actor)

for vehicle in spawned_cars: try: vehicle.destroy() except Exception as e: print("Failed to destroy car:", e)

``

00Dan00 commented 2 weeks ago

Sorry not sure why the code is formated this poorly.

So in general .destroy() just sometimes crashes my environment

Blyron commented 2 weeks ago

You have to call at least one time tick() after the creation of vehicles in order to be able to destroying them properly.