Fix long-standing crash when a vehicle is destroyed

This commit is contained in:
nsubiron 2018-07-28 13:04:14 +02:00
parent c785437f08
commit 67643485cc
2 changed files with 20 additions and 4 deletions

View File

@ -91,7 +91,8 @@ void AWheeledVehicleAIController::Possess(APawn *aPawn)
{ {
Super::Possess(aPawn); Super::Possess(aPawn);
if (IsPossessingAVehicle()) { if (IsPossessingAVehicle())
{
UE_LOG(LogCarla, Error, TEXT("Controller already possessing a vehicle!")); UE_LOG(LogCarla, Error, TEXT("Controller already possessing a vehicle!"));
return; return;
} }
@ -108,13 +109,26 @@ void AWheeledVehicleAIController::Possess(APawn *aPawn)
} }
} }
void AWheeledVehicleAIController::UnPossess()
{
Super::UnPossess();
Vehicle = nullptr;
}
void AWheeledVehicleAIController::Tick(const float DeltaTime) void AWheeledVehicleAIController::Tick(const float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
if (!IsPossessingAVehicle())
{
return;
}
TickAutopilotController(); TickAutopilotController();
if (bAutopilotEnabled) { if (bAutopilotEnabled)
{
Vehicle->ApplyVehicleControl(AutopilotControl); Vehicle->ApplyVehicleControl(AutopilotControl);
} }
} }

View File

@ -42,9 +42,11 @@ public:
/// @{ /// @{
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;
/// @} /// @}
// =========================================================================== // ===========================================================================