Fix server was sending deleted data
This commit is contained in:
parent
e0928ff9ed
commit
201be068c7
|
@ -66,7 +66,7 @@ public class Carla : ModuleRules
|
|||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC) Project Settings.
|
||||
|
||||
#include "carla/server/CarlaMeasurements.h"
|
||||
|
||||
#include "carla/Logging.h"
|
||||
|
||||
namespace carla {
|
||||
namespace server {
|
||||
|
||||
void CarlaMeasurements::Write(const carla_measurements &measurements) {
|
||||
_measurements = measurements;
|
||||
const auto size = measurements.number_of_non_player_agents * sizeof(carla_agent);
|
||||
if (_agents_buffer_size < size) {
|
||||
log_info("allocating agents buffer of", size, "bytes");
|
||||
_agents_buffer = std::make_unique<unsigned char[]>(size);
|
||||
_agents_buffer_size = size;
|
||||
}
|
||||
std::memcpy(_agents_buffer.get(), measurements.non_player_agents, size);
|
||||
_measurements.non_player_agents =
|
||||
reinterpret_cast<const carla_agent *>(_agents_buffer.get());
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace carla
|
|
@ -0,0 +1,34 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC) Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "carla/NonCopyable.h"
|
||||
#include "carla/server/CarlaServerAPI.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace carla {
|
||||
namespace server {
|
||||
|
||||
/// Holds a carla_measurements and keeps its own copy of the dynamically
|
||||
/// allocated data.
|
||||
class CarlaMeasurements : private NonCopyable {
|
||||
public:
|
||||
|
||||
void Write(const carla_measurements &measurements);
|
||||
|
||||
const carla_measurements &measurements() const {
|
||||
return _measurements;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
carla_measurements _measurements;
|
||||
|
||||
std::unique_ptr<unsigned char[]> _agents_buffer = nullptr;
|
||||
|
||||
uint32_t _agents_buffer_size = 0u;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace carla
|
|
@ -3,6 +3,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "carla/NonCopyable.h"
|
||||
#include "carla/server/CarlaMeasurements.h"
|
||||
#include "carla/server/CarlaServerAPI.h"
|
||||
#include "carla/server/ImagesMessage.h"
|
||||
|
||||
namespace carla {
|
||||
|
@ -14,12 +16,12 @@ namespace server {
|
|||
void Write(
|
||||
const carla_measurements &measurements,
|
||||
const_array_view<carla_image> images) {
|
||||
_measurements = measurements;
|
||||
_measurements.Write(measurements);
|
||||
_images.Write(images);
|
||||
}
|
||||
|
||||
const carla_measurements &measurements() const {
|
||||
return _measurements;
|
||||
return _measurements.measurements();
|
||||
}
|
||||
|
||||
const_buffer images() const {
|
||||
|
@ -28,7 +30,7 @@ namespace server {
|
|||
|
||||
private:
|
||||
|
||||
carla_measurements _measurements;
|
||||
CarlaMeasurements _measurements;
|
||||
|
||||
ImagesMessage _images;
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ import carla_server_pb2 as carla_protocol
|
|||
CarlaSettings = """
|
||||
[CARLA/Server]
|
||||
SynchronousMode=true
|
||||
SendNonPlayerAgentsInfo=false
|
||||
SendNonPlayerAgentsInfo=true
|
||||
[CARLA/LevelSettings]
|
||||
NumberOfVehicles=10
|
||||
NumberOfPedestrians=20
|
||||
|
@ -150,8 +150,9 @@ def test_carla_client():
|
|||
|
||||
logging.info('waiting for the scene description')
|
||||
data = client.read_scene_description()
|
||||
data = data.player_start_spots
|
||||
logging.info('received %d bytes of player start locations', len(data) if data is not None else 0)
|
||||
logging.info('received %d player start locations', len(data.player_start_spots))
|
||||
for spot in data.player_start_spots:
|
||||
logging.info(spot)
|
||||
|
||||
logging.info('sending episode start')
|
||||
client.write_episode_start(2)
|
||||
|
@ -176,6 +177,8 @@ def test_carla_client():
|
|||
else:
|
||||
logging.info('received valid measurements')
|
||||
logging.info('received info of %d agents', len(data.non_player_agents))
|
||||
for agent in data.non_player_agents:
|
||||
logging.info(agent)
|
||||
logging.info('waiting for images')
|
||||
data = client.read_images()
|
||||
logging.info('received %d bytes of images', len(data) if data is not None else 0)
|
||||
|
|
Loading…
Reference in New Issue