Fix crash empty actor getting serialized
This commit is contained in:
parent
b80f70b8b9
commit
26198adab3
|
@ -11,10 +11,6 @@
|
|||
#include "carla/geom/Location.h"
|
||||
#include "carla/geom/Vector3D.h"
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
# include "GameFramework/Actor.h"
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
namespace carla {
|
||||
namespace geom {
|
||||
|
||||
|
@ -43,14 +39,9 @@ namespace geom {
|
|||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
explicit BoundingBox(const AActor *AnActor) {
|
||||
DEBUG_ASSERT(AnActor != nullptr);
|
||||
constexpr bool bOnlyCollidingComponents = true;
|
||||
FVector Origin, BoxExtent;
|
||||
AnActor->GetActorBounds(bOnlyCollidingComponents, Origin, BoxExtent);
|
||||
location = Location(Origin);
|
||||
extent = Vector3D(1e-2f * BoxExtent.X, 1e-2f * BoxExtent.Y, 1e-2f * BoxExtent.Z);
|
||||
}
|
||||
BoundingBox(const FVector &Origin, const FVector &BoxExtent)
|
||||
: location(Origin),
|
||||
extent(1e-2f * BoxExtent.X, 1e-2f * BoxExtent.Y, 1e-2f * BoxExtent.Z) {}
|
||||
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
|
||||
#include <cstring>
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
# include "Carla/Actor/ActorView.h"
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
namespace carla {
|
||||
namespace rpc {
|
||||
|
||||
|
@ -51,25 +47,6 @@ namespace rpc {
|
|||
|
||||
/// @}
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
Actor(FActorView View)
|
||||
: id(View.GetActorId()),
|
||||
description(*View.GetActorDescription()),
|
||||
bounding_box(View.GetActor()) {
|
||||
DEBUG_ASSERT(View.IsValid());
|
||||
}
|
||||
|
||||
Actor(FActorView View, const streaming::Token &StreamToken)
|
||||
: id(View.GetActorId()),
|
||||
description(*View.GetActorDescription()),
|
||||
bounding_box(View.GetActor()),
|
||||
stream_token(StreamToken.data.begin(), StreamToken.data.end()) {
|
||||
DEBUG_ASSERT(View.IsValid());
|
||||
}
|
||||
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
MSGPACK_DEFINE_ARRAY(id, description, bounding_box, stream_token);
|
||||
};
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ void ACollisionSensor::OnCollisionEvent(
|
|||
FVector NormalImpulse,
|
||||
const FHitResult &Hit)
|
||||
{
|
||||
if ((Episode != nullptr) && (GameInstance != nullptr))
|
||||
if ((Episode != nullptr) && (GameInstance != nullptr) && (Actor != nullptr) && (OtherActor != nullptr))
|
||||
{
|
||||
const auto &Registry = Episode->GetActorRegistry();
|
||||
const auto &Server = GameInstance->GetServer();
|
||||
|
|
|
@ -107,20 +107,35 @@ private:
|
|||
::AttachActors(Child.GetActor(), Parent.GetActor());
|
||||
}
|
||||
|
||||
carla::geom::BoundingBox GetActorBoundingBox(const AActor &Actor)
|
||||
{
|
||||
constexpr bool bOnlyCollidingComponents = true;
|
||||
FVector Origin, BoxExtent;
|
||||
Actor.GetActorBounds(bOnlyCollidingComponents, Origin, BoxExtent);
|
||||
return {Origin, BoxExtent};
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
carla::rpc::Actor SerializeActor(FActorView ActorView)
|
||||
{
|
||||
carla::rpc::Actor Actor;
|
||||
Actor.id = ActorView.GetActorId();
|
||||
if (ActorView.IsValid())
|
||||
{
|
||||
Actor.description = *ActorView.GetActorDescription();
|
||||
Actor.bounding_box = GetActorBoundingBox(*ActorView.GetActor());
|
||||
auto *Sensor = Cast<ASensor>(ActorView.GetActor());
|
||||
if (Sensor != nullptr)
|
||||
{
|
||||
auto Stream = GetSensorStream(ActorView, *Sensor);
|
||||
return {ActorView, Stream.token()};
|
||||
const auto &Token = Stream.token();
|
||||
Actor.stream_token = decltype(Actor.stream_token)(std::begin(Token.data), std::end(Token.data));
|
||||
}
|
||||
} else {
|
||||
UE_LOG(LogCarla, Warning, TEXT("Trying to serialize invalid actor"));
|
||||
}
|
||||
return ActorView;
|
||||
return Actor;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -173,7 +188,7 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
|
||||
RespondErrorStr("unable to find spectator");
|
||||
}
|
||||
return ActorView;
|
||||
return SerializeActor(ActorView);
|
||||
});
|
||||
|
||||
Server.BindSync("get_weather_parameters", [this]() -> cr::WeatherParameters {
|
||||
|
|
Loading…
Reference in New Issue