#1119 make sure streams are discarded when the sensor is destroyed
This commit is contained in:
parent
159206b298
commit
bd398acf28
|
@ -32,7 +32,10 @@ namespace detail {
|
|||
// stopped.
|
||||
for (auto &pair : _stream_map) {
|
||||
try {
|
||||
pair.second->ClearSessions();
|
||||
auto stream_state = pair.second.lock();
|
||||
if (stream_state != nullptr) {
|
||||
stream_state->ClearSessions();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
log_error("failed to clear sessions:", e.what());
|
||||
}
|
||||
|
@ -56,22 +59,27 @@ namespace detail {
|
|||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
auto search = _stream_map.find(session->get_stream_id());
|
||||
if (search != _stream_map.end()) {
|
||||
DEBUG_ASSERT(search->second != nullptr);
|
||||
search->second->ConnectSession(std::move(session));
|
||||
auto stream_state = search->second.lock();
|
||||
if (stream_state != nullptr) {
|
||||
stream_state->ConnectSession(std::move(session));
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
log_error("Invalid session: no stream available with id", session->get_stream_id());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Dispatcher::DeregisterSession(std::shared_ptr<Session> session) {
|
||||
DEBUG_ASSERT(session != nullptr);
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
auto search = _stream_map.find(session->get_stream_id());
|
||||
if (search != _stream_map.end()) {
|
||||
DEBUG_ASSERT(search->second != nullptr);
|
||||
search->second->DisconnectSession(session);
|
||||
auto stream_state = search->second.lock();
|
||||
if (stream_state != nullptr) {
|
||||
stream_state->DisconnectSession(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace detail {
|
|||
/// them alive the whole run.
|
||||
std::unordered_map<
|
||||
stream_id_type,
|
||||
std::shared_ptr<StreamStateBase>> _stream_map;
|
||||
std::weak_ptr<StreamStateBase>> _stream_map;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "Carla.h"
|
||||
#include "Carla/Sensor/Sensor.h"
|
||||
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
|
||||
|
||||
void ASensor::Set(const FActorDescription &Description)
|
||||
{
|
||||
// set the tick interval of the sensor
|
||||
if (Description.Variations.Contains("sensor_tick"))
|
||||
{
|
||||
SetActorTickInterval(
|
||||
UActorBlueprintFunctionLibrary::ActorAttributeToFloat(Description.Variations["sensor_tick"],
|
||||
0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
void ASensor::EndPlay(EEndPlayReason::Type EndPlayReason)
|
||||
{
|
||||
Super::EndPlay(EndPlayReason);
|
||||
Stream = FDataStream();
|
||||
}
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
|
||||
#include "Carla/Sensor/DataStream.h"
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
|
||||
#include "Sensor.generated.h"
|
||||
|
||||
struct FActorDescription;
|
||||
|
||||
/// Base class for sensors.
|
||||
UCLASS(Abstract, hidecategories = (Collision, Attachment, Actor))
|
||||
class CARLA_API ASensor : public AActor
|
||||
|
@ -22,16 +22,7 @@ class CARLA_API ASensor : public AActor
|
|||
|
||||
public:
|
||||
|
||||
virtual void Set(const FActorDescription &Description)
|
||||
{
|
||||
// set the tick interval of the sensor
|
||||
if (Description.Variations.Contains("sensor_tick"))
|
||||
{
|
||||
SetActorTickInterval(
|
||||
UActorBlueprintFunctionLibrary::ActorAttributeToFloat(Description.Variations["sensor_tick"],
|
||||
0.0f));
|
||||
}
|
||||
}
|
||||
virtual void Set(const FActorDescription &Description);
|
||||
|
||||
/// Replace the FDataStream associated with this sensor.
|
||||
///
|
||||
|
@ -43,6 +34,8 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
void EndPlay(EEndPlayReason::Type EndPlayReason) override;
|
||||
|
||||
/// Return the FDataStream associated with this sensor.
|
||||
FDataStream &GetDataStream()
|
||||
{
|
||||
|
|
|
@ -161,6 +161,10 @@ private:
|
|||
return it->second;
|
||||
}
|
||||
|
||||
void ClearSensorStream(FActorView ActorView) {
|
||||
_StreamMap.erase(ActorView.GetActorId());
|
||||
}
|
||||
|
||||
std::unordered_map<FActorView::IdType, carla::streaming::Stream> _StreamMap;
|
||||
};
|
||||
|
||||
|
@ -272,6 +276,7 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
UE_LOG(LogCarlaServer, Warning, TEXT("unable to destroy actor: not found"));
|
||||
return false;
|
||||
}
|
||||
ClearSensorStream(ActorView);
|
||||
return Episode->DestroyActor(ActorView.GetActor());
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue