From 67643485ccf2a4906f0ef7e76e842a16cad87254 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Sat, 28 Jul 2018 13:04:14 +0200 Subject: [PATCH] Fix long-standing crash when a vehicle is destroyed --- .../Vehicle/WheeledVehicleAIController.cpp | 18 ++++++++++++++++-- .../Carla/Vehicle/WheeledVehicleAIController.h | 6 ++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.cpp index f97a71e6c..f94283463 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.cpp @@ -91,7 +91,8 @@ void AWheeledVehicleAIController::Possess(APawn *aPawn) { Super::Possess(aPawn); - if (IsPossessingAVehicle()) { + if (IsPossessingAVehicle()) + { UE_LOG(LogCarla, Error, TEXT("Controller already possessing a vehicle!")); return; } @@ -108,13 +109,26 @@ void AWheeledVehicleAIController::Possess(APawn *aPawn) } } +void AWheeledVehicleAIController::UnPossess() +{ + Super::UnPossess(); + + Vehicle = nullptr; +} + void AWheeledVehicleAIController::Tick(const float DeltaTime) { Super::Tick(DeltaTime); + if (!IsPossessingAVehicle()) + { + return; + } + TickAutopilotController(); - if (bAutopilotEnabled) { + if (bAutopilotEnabled) + { Vehicle->ApplyVehicleControl(AutopilotControl); } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.h index 2e7f36bf9..b80be8674 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/WheeledVehicleAIController.h @@ -42,9 +42,11 @@ public: /// @{ public: - virtual void Possess(APawn *aPawn) override; + void Possess(APawn *aPawn) override; - virtual void Tick(float DeltaTime) override; + void UnPossess() override; + + void Tick(float DeltaTime) override; /// @} // ===========================================================================