Add temporary workaround for the memory blowup issue (#8098)
* Add temporary workaround for the memory blowup issue during save_to_disk. * Add more fixes on the server side. Update gitignore to remove the _out folder in PythonAPI/examples. * Enable clangd support. (#8104) * Enable clangd support. * Disable CMAKE_EXPORT_COMPILE_COMMANDS by default. * Revert unwanted target rename. * Solves the crash on server side We still have an unhandled exception on client side, but it doesn't affect nominal behaviour. * Revert "Merge branch 'marcel/leak-workaround' of https://github.com/carla-simulator/carla into marcel/leak-workaround" This reverts commit89c211e780
, reversing changes made to908c203fca
. * Reapply "Merge branch 'marcel/leak-workaround' of https://github.com/carla-simulator/carla into marcel/leak-workaround" This reverts commitfc2402efdb
. * Fixed crash on client side Now it's both client and server crashes fixed. By removing posts but keeping async read/write, we make sure saving to disk is sequential but there's no error if it gets interrupted. * Cleanup of Changes -- Preparation for PR --------- Co-authored-by: Jorge Virgos <jorgevirgos.dev@gmail.com>
This commit is contained in:
parent
592eb46f43
commit
239b73e849
|
@ -15,7 +15,6 @@
|
||||||
#include <boost/asio/connect.hpp>
|
#include <boost/asio/connect.hpp>
|
||||||
#include <boost/asio/read.hpp>
|
#include <boost/asio/read.hpp>
|
||||||
#include <boost/asio/write.hpp>
|
#include <boost/asio/write.hpp>
|
||||||
#include <boost/asio/post.hpp>
|
|
||||||
#include <boost/asio/bind_executor.hpp>
|
#include <boost/asio/bind_executor.hpp>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
@ -86,7 +85,6 @@ namespace tcp {
|
||||||
|
|
||||||
void Client::Connect() {
|
void Client::Connect() {
|
||||||
auto self = shared_from_this();
|
auto self = shared_from_this();
|
||||||
boost::asio::post(_strand, [this, self]() {
|
|
||||||
if (_done) {
|
if (_done) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,18 +137,15 @@ namespace tcp {
|
||||||
|
|
||||||
log_debug("streaming client: connecting to", ep);
|
log_debug("streaming client: connecting to", ep);
|
||||||
_socket.async_connect(ep, boost::asio::bind_executor(_strand, handle_connect));
|
_socket.async_connect(ep, boost::asio::bind_executor(_strand, handle_connect));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::Stop() {
|
void Client::Stop() {
|
||||||
_connection_timer.cancel();
|
_connection_timer.cancel();
|
||||||
auto self = shared_from_this();
|
auto self = shared_from_this();
|
||||||
boost::asio::post(_strand, [this, self]() {
|
|
||||||
_done = true;
|
_done = true;
|
||||||
if (_socket.is_open()) {
|
if (_socket.is_open()) {
|
||||||
_socket.close();
|
_socket.close();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::Reconnect() {
|
void Client::Reconnect() {
|
||||||
|
@ -165,7 +160,6 @@ namespace tcp {
|
||||||
|
|
||||||
void Client::ReadData() {
|
void Client::ReadData() {
|
||||||
auto self = shared_from_this();
|
auto self = shared_from_this();
|
||||||
boost::asio::post(_strand, [this, self]() {
|
|
||||||
if (_done) {
|
if (_done) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +176,7 @@ namespace tcp {
|
||||||
// Move the buffer to the callback function and start reading the next
|
// Move the buffer to the callback function and start reading the next
|
||||||
// piece of data.
|
// piece of data.
|
||||||
// log_debug("streaming client: success reading data, calling the callback");
|
// log_debug("streaming client: success reading data, calling the callback");
|
||||||
boost::asio::post(_strand, [self, message]() { self->_callback(message->pop()); });
|
_callback(message->pop());
|
||||||
ReadData();
|
ReadData();
|
||||||
} else {
|
} else {
|
||||||
// As usual, if anything fails start over from the very top.
|
// As usual, if anything fails start over from the very top.
|
||||||
|
@ -219,7 +213,6 @@ namespace tcp {
|
||||||
_socket,
|
_socket,
|
||||||
message->size_as_buffer(),
|
message->size_as_buffer(),
|
||||||
boost::asio::bind_executor(_strand, handle_read_header));
|
boost::asio::bind_executor(_strand, handle_read_header));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tcp
|
} // namespace tcp
|
||||||
|
|
|
@ -79,7 +79,6 @@ namespace tcp {
|
||||||
DEBUG_ASSERT(message != nullptr);
|
DEBUG_ASSERT(message != nullptr);
|
||||||
DEBUG_ASSERT(!message->empty());
|
DEBUG_ASSERT(!message->empty());
|
||||||
auto self = shared_from_this();
|
auto self = shared_from_this();
|
||||||
boost::asio::post(_strand, [=]() {
|
|
||||||
if (!_socket.is_open()) {
|
if (!_socket.is_open()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -111,11 +110,8 @@ namespace tcp {
|
||||||
log_debug("session", _session_id, ": sending message of", message->size(), "bytes");
|
log_debug("session", _session_id, ": sending message of", message->size(), "bytes");
|
||||||
|
|
||||||
_deadline.expires_from_now(_timeout);
|
_deadline.expires_from_now(_timeout);
|
||||||
boost::asio::async_write(
|
boost::asio::async_write(_socket, message->GetBufferSequence(),
|
||||||
_socket,
|
boost::asio::bind_executor(_strand, handle_sent));
|
||||||
message->GetBufferSequence(),
|
|
||||||
handle_sent);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSession::Close() {
|
void ServerSession::Close() {
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
carla.so
|
_out/
|
||||||
carla.pyd
|
|
||||||
|
|
|
@ -226,7 +226,16 @@ namespace ImageUtil
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void ReadImageDataAsyncCommand(
|
struct ReadImageDataContext
|
||||||
|
{
|
||||||
|
EPixelFormat Format;
|
||||||
|
FIntPoint Size;
|
||||||
|
ReadImageDataAsyncCallback Callback;
|
||||||
|
TUniquePtr<FRHIGPUTextureReadback> Readback;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void ReadImageDataBegin(
|
||||||
|
ReadImageDataContext& Self,
|
||||||
UTextureRenderTarget2D& RenderTarget,
|
UTextureRenderTarget2D& RenderTarget,
|
||||||
ReadImageDataAsyncCallback&& Callback)
|
ReadImageDataAsyncCallback&& Callback)
|
||||||
{
|
{
|
||||||
|
@ -239,12 +248,13 @@ namespace ImageUtil
|
||||||
auto Texture = Resource->GetRenderTargetTexture();
|
auto Texture = Resource->GetRenderTargetTexture();
|
||||||
if (Texture == nullptr)
|
if (Texture == nullptr)
|
||||||
return;
|
return;
|
||||||
auto Readback = MakeUnique<FRHIGPUTextureReadback>(
|
Self.Callback = std::move(Callback);
|
||||||
|
Self.Readback = MakeUnique<FRHIGPUTextureReadback>(
|
||||||
TEXT("ReadImageData-Readback"));
|
TEXT("ReadImageData-Readback"));
|
||||||
auto Size = Texture->GetSizeXY();
|
Self.Size = Texture->GetSizeXY();
|
||||||
auto Format = Texture->GetFormat();
|
Self.Format = Texture->GetFormat();
|
||||||
auto ResolveRect = FResolveRect();
|
auto ResolveRect = FResolveRect();
|
||||||
Readback->EnqueueCopy(CmdList, Texture, ResolveRect);
|
Self.Readback->EnqueueCopy(CmdList, Texture, ResolveRect);
|
||||||
|
|
||||||
auto Query = RenderQueryPool->AllocateQuery();
|
auto Query = RenderQueryPool->AllocateQuery();
|
||||||
CmdList.EndRenderQuery(Query.GetQuery());
|
CmdList.EndRenderQuery(Query.GetQuery());
|
||||||
|
@ -252,26 +262,42 @@ namespace ImageUtil
|
||||||
uint64 DeltaTime;
|
uint64 DeltaTime;
|
||||||
RHIGetRenderQueryResult(Query.GetQuery(), DeltaTime, true);
|
RHIGetRenderQueryResult(Query.GetQuery(), DeltaTime, true);
|
||||||
Query.ReleaseQuery();
|
Query.ReleaseQuery();
|
||||||
|
}
|
||||||
|
|
||||||
AsyncTask(
|
static void ReadImageDataEnd(
|
||||||
ENamedThreads::HighTaskPriority, [
|
ReadImageDataContext& Self)
|
||||||
Readback = MoveTemp(Readback),
|
|
||||||
Callback = std::move(Callback),
|
|
||||||
Size,
|
|
||||||
Format]
|
|
||||||
{
|
{
|
||||||
while (!Readback->IsReady())
|
|
||||||
std::this_thread::yield();
|
|
||||||
int32 RowPitch, BufferHeight;
|
int32 RowPitch, BufferHeight;
|
||||||
auto MappedPtr = Readback->Lock(RowPitch, &BufferHeight);
|
auto MappedPtr = Self.Readback->Lock(RowPitch, &BufferHeight);
|
||||||
if (MappedPtr != nullptr)
|
if (MappedPtr != nullptr)
|
||||||
{
|
{
|
||||||
ScopedCallback Unlock = [&] { Readback->Unlock(); };
|
ScopedCallback Unlock = [&] { Self.Readback->Unlock(); };
|
||||||
Callback(MappedPtr, RowPitch, BufferHeight, Format, Size);
|
Self.Callback(MappedPtr, RowPitch, BufferHeight, Self.Format, Self.Size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ReadImageDataEndAsync(
|
||||||
|
ReadImageDataContext&& Self)
|
||||||
|
{
|
||||||
|
AsyncTask(
|
||||||
|
ENamedThreads::HighTaskPriority, [
|
||||||
|
Self = std::move(Self)]() mutable
|
||||||
|
{
|
||||||
|
while (!Self.Readback->IsReady())
|
||||||
|
std::this_thread::yield();
|
||||||
|
ReadImageDataEnd(Self);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ReadImageDataAsyncCommand(
|
||||||
|
UTextureRenderTarget2D& RenderTarget,
|
||||||
|
ReadImageDataAsyncCallback&& Callback)
|
||||||
|
{
|
||||||
|
ReadImageDataContext Context = { };
|
||||||
|
ReadImageDataBegin(Context, RenderTarget, std::move(Callback));
|
||||||
|
ReadImageDataEndAsync(std::move(Context));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ReadImageDataAsync(
|
bool ReadImageDataAsync(
|
||||||
|
@ -287,14 +313,14 @@ namespace ImageUtil
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ENQUEUE_RENDER_COMMAND(ReadImageDataAsyncCmd)([
|
ENQUEUE_RENDER_COMMAND(ReadImageDataAsyncCmd)([
|
||||||
&RenderTarget,
|
&RenderTarget, Callback = std::move(Callback)
|
||||||
Callback = std::move(Callback)
|
|
||||||
](auto& CmdList) mutable
|
](auto& CmdList) mutable
|
||||||
{
|
{
|
||||||
ReadImageDataAsyncCommand(
|
ReadImageDataContext Context = { };
|
||||||
RenderTarget,
|
ReadImageDataBegin(Context, RenderTarget, std::move(Callback));
|
||||||
std::move(Callback));
|
ReadImageDataEnd(Context);
|
||||||
});
|
});
|
||||||
|
FlushRenderingCommands();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue