Fixes nullptr bug in CarlaRecorder::AddCollision (PR resubmit, for Axel1092) (#4727)

* Fixed bug causing the server to sigsegv when a vehicle collides an environment object in recording mode

* fix include for windows

Co-authored-by: Axel1092 <35765780+Axel1092@users.noreply.github.com>
Co-authored-by: bernatx <berni2berni>
This commit is contained in:
amparore 2021-11-08 10:17:19 +01:00 committed by GitHub
parent 2199d90e1f
commit 62630cef0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 14 deletions

View File

@ -21,6 +21,7 @@
* Added physical simulation to vehicle doors, capable of opening and closing
* Fixed the import of props without any map
* Fixed global route planner crash when being used at maps without lane markings
* Fixed bug causing the server to sigsegv when a vehicle collides an environment object in recording mode.
* Improved collision detection of the Python agents
* Added the new VehicleLightStage to the Traffic Manager to dynamically update the vehicle lights.
* Added two new examples to PythonAPI/util: Conversion of OpenStreetMaps to OpenDRIVE maps `osm_to_xodr.py` and Extraction of map spawn points `extract_spawn_points.py`

View File

@ -469,22 +469,34 @@ void ACarlaRecorder::AddCollision(AActor *Actor1, AActor *Actor2)
Collision.IsActor2Hero = false;
// check actor 1
if (Episode->GetActorRegistry().FindCarlaActor(Actor1)->GetActorInfo() != nullptr)
{
auto *Role = Episode->GetActorRegistry().FindCarlaActor(Actor1)->GetActorInfo()->Description.Variations.Find("role_name");
if (Role != nullptr)
Collision.IsActor1Hero = (Role->Value == "hero");
FCarlaActor *FoundActor1 = Episode->GetActorRegistry().FindCarlaActor(Actor1);
if (FoundActor1 != nullptr) {
if (FoundActor1->GetActorInfo() != nullptr)
{
auto Role = FoundActor1->GetActorInfo()->Description.Variations.Find("role_name");
if (Role != nullptr)
Collision.IsActor1Hero = (Role->Value == "hero");
}
Collision.DatabaseId1 = FoundActor1->GetActorId();
}
else {
Collision.DatabaseId1 = uint32_t(-1); // actor1 is not a registered Carla actor
}
Collision.DatabaseId1 = Episode->GetActorRegistry().FindCarlaActor(Actor1)->GetActorId();
// check actor 2
if (Episode->GetActorRegistry().FindCarlaActor(Actor2)->GetActorInfo() != nullptr)
{
auto Role = Episode->GetActorRegistry().FindCarlaActor(Actor2)->GetActorInfo()->Description.Variations.Find("role_name");
if (Role != nullptr)
Collision.IsActor2Hero = (Role->Value == "hero");
FCarlaActor *FoundActor2 = Episode->GetActorRegistry().FindCarlaActor(Actor2);
if (FoundActor2 != nullptr) {
if (FoundActor2->GetActorInfo() != nullptr)
{
auto Role = FoundActor2->GetActorInfo()->Description.Variations.Find("role_name");
if (Role != nullptr)
Collision.IsActor2Hero = (Role->Value == "hero");
}
Collision.DatabaseId2 = FoundActor2->GetActorId();
}
else {
Collision.DatabaseId2 = uint32_t(-1); // actor2 is not a registered Carla actor
}
Collision.DatabaseId2 = Episode->GetActorRegistry().FindCarlaActor(Actor2)->GetActorId();
Collisions.Add(std::move(Collision));
}

View File

@ -664,9 +664,18 @@ std::string CarlaRecorderQuery::QueryCollisions(std::string Filename, char Categ
Collision.Read(File);
int Valid = 0;
// get categories for both actors
uint8_t Type1 = Categories[Actors[Collision.DatabaseId1].Type];
uint8_t Type2 = Categories[Actors[Collision.DatabaseId2].Type];
uint8_t Type1, Type2;
if (Collision.DatabaseId1 != uint32_t(-1))
Type1 = Categories[Actors[Collision.DatabaseId1].Type];
else
Type1 = 'o'; // other non-actor object
if (Collision.DatabaseId2 != uint32_t(-1))
Type2 = Categories[Actors[Collision.DatabaseId2].Type];
else
Type2 = 'o'; // other non-actor object
// filter actor 1
if (Category1 == 'a')

View File

@ -7,6 +7,7 @@
#include "Carla.h"
#include "Carla/Trigger/TriggerFactory.h"
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
#include "Carla/Game/CarlaGameInstance.h"
#include "Carla/Game/CarlaStatics.h"
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"