[Python] Walkers and vehicles spawn but do not move — Segfault on training start (4070 Ti...

Discussão em 'Python' iniciado por Stack, Julho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I’m running a multi‑agent autonomous driving setup with CARLA 0.9.15 and Stable‑Baselines3 1.7.0 on Ubuntu 20.04. Everything spawns correctly vehicles, walkers, AI controllers but when training begins, agents never move. A few seconds later I get:

    Segmentation fault (core dumped)

    I’ve confirmed that:

    The Gym environment wraps (DummyVecEnv → VecMonitor) and resets without error.

    policy.load() succeeds and SB3’s model.learn() is entered.

    actor.apply_control() is called every step.

    Actors exist and aren’t destroyed prematurely.

    Yet zero throttle, brake, steer ever registers in CARLA.What I’ve Tried

    Native floats for controlsConverted all np.float32 to Python float. No change—controls still zero and crash persists.

    Synchronous vs asynchronous mode

    Enabled synchronous mode with world.apply_settings(sync=True) + explicit world.tick().

    Tried purely asynchronous mode.Vehicles never budged in both.

    Monitor/VecMonitor fixes

    Removed double‑wrapping warnings by only using VecMonitor.

    Ensured env.step() returns valid (obs, reward, done, truncated, info).Still no movement.

    Traffic Manager & autopilotDisabled CARLA’s Traffic Manager and autopilot on spawned vehicles. Expected manual controls to override; nothing happened.

    GPU on/off

    With CUDA: crash after ~10 s.

    Without CUDA: no crash but still zero movement.

    Try/except around step/resetCaptured and logged any exceptions—none thrown until segfault.

    Version alignmentVerified client/server versions match (modulo “-dirty” tag). Confirmed Python API from 0.9.15 build.

    Spawn & Training Logs (abridged)[2025.07.06-10.30.52:525][126]LogCarla: Spawning actor 'vehicle.mitsubishi.fusorosa'

    [2025.07.06-10.30.52:528][126]LogBlueprintUserMessages: MaterialNotFound

    [2025.07.06-10.30.52:559][128]LogCarla: Spawning actor 'vehicle.jeep.wrangler_rubicon'

    [2025.07.06-10.30.52:626][132]LogCarla: Spawning actor 'walker.pedestrian.0002'

    [2025.07.06-10.30.53:010][155]LogCarlaServer: New episode 'Town03' started

    Using cuda device

    ...

    Starting training with 1000 timesteps…

    Using policy: ActorCriticPolicy(…)

    WARNING: Version mismatch: Client API = 0.9.15; Simulator API = 0.9.15-dirty

    Segmentation fault (core dumped)

    and if need to give code as i have made different files for different function https://github.com/Yash-weeber/Carlarrl.git this is the git link for the files if you want to try


    import carla
    import gymnasium as gym
    from stable_baselines3 import PPO
    from stable_baselines3.common.vec_env import DummyVecEnv, VecMonitor

    class SimpleCarlaEnv(gym.Env):
    def __init__(self):
    super().__init__()

    self.client = carla.Client('localhost', 2000)
    self.client.set_timeout(5.0)
    self.world = self.client.load_world('Town03')
    # 2) sync mode
    settings = self.world.get_settings()
    settings.synchronous_mode = True
    settings.fixed_delta_seconds = 0.05
    self.world.apply_settings(settings)
    # 3) spawn one vehicle
    bp = self.world.get_blueprint_library().filter('vehicle.*')[0]
    spawn = self.world.get_map().get_spawn_points()[0]
    self.vehicle = self.world.spawn_actor(bp, spawn)


    self.observation_space = gym.spaces.Box(-1000, 1000, shape=(3,), dtype=float)

    self.action_space = gym.spaces.Box(-1.0, 1.0, shape=(3,), dtype=float)

    def reset(self):
    t = self.vehicle.get_transform()
    return (t.location.x, t.location.y, t.rotation.yaw), {}

    def step(self, action):

    thr, st, br = map(float, action)
    ctrl = carla.VehicleControl(throttle=thr, steer=st, brake=br)
    self.vehicle.apply_control(ctrl)
    # advance the world
    self.world.tick()
    t = self.vehicle.get_transform()
    obs = (t.location.x, t.location.y, t.rotation.yaw)
    return obs, 0.0, False, False, {}

    def close(self):
    self.vehicle.destroy()
    s = self.world.get_settings()
    s.synchronous_mode = False
    self.world.apply_settings(s)

    if __name__ == '__main__':
    # wrap & train just 1,000 steps
    env = DummyVecEnv([SimpleCarlaEnv])
    env = VecMonitor(env)
    model = PPO('MlpPolicy', env, verbose=1, device='cuda')
    model.learn(total_timesteps=1000)


    Please help with this as im really confused on this for past 3 days

    Continue reading...

Compartilhe esta Página