Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destroying actors from a list #7653

Closed
00Dan00 opened this issue May 15, 2024 · 2 comments
Closed

destroying actors from a list #7653

00Dan00 opened this issue May 15, 2024 · 2 comments
Assignees

Comments

@00Dan00
Copy link

00Dan00 commented May 15, 2024

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()
spawned_cars = []
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 00Dan00 closed this as completed May 15, 2024
@00Dan00 00Dan00 reopened this May 15, 2024
@00Dan00
Copy link
Author

00Dan00 commented May 15, 2024

Sorry not sure why the code is formated this poorly.

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

@Blyron
Copy link
Contributor

Blyron commented May 16, 2024

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

@Blyron Blyron self-assigned this May 16, 2024
@Blyron Blyron closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants