From 4b5cb3e20588c4b69c55840f3406c0af010ebbdc Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 16 May 2021 01:36:17 +0200 Subject: [PATCH] Initialize thread locals later This shouldn't be necessary, but maybe this helps with the issue where the optional is suddenly a nullopt. --- src/common/communication/vst3.h | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/common/communication/vst3.h b/src/common/communication/vst3.h index cf7b4957..56e965a0 100644 --- a/src/common/communication/vst3.h +++ b/src/common/communication/vst3.h @@ -206,28 +206,22 @@ class Vst3MessageHandler : public AdHocSocketHandler { template void receive_messages(std::optional> logging, F callback) { - thread_local std::vector persistent_buffer{}; - // This is an `std::variant<>`, so this will actually persistently store - // a copy of all possible requests even if we're only interested in the - // process data, since that's the only object where allocations can - // happen. The other objects we're storing here are very small, so the - // extra wasted memory shouldn't matter much. - thread_local std::optional persistent_object( - persistent_buffers ? std::make_optional() : std::nullopt); - - // FIXME: In some cases this didn't get initialized for some reason. - // Figure out why. - if constexpr (persistent_buffers) { - if (!persistent_object) { - persistent_object.emplace(); - } - } - // Reading, processing, and writing back the response for the requests // we receive works in the same way regardless of which socket we're // using const auto process_message = [&](boost::asio::local::stream_protocol::socket& socket) { + thread_local std::vector persistent_buffer{}; + // This is an `std::variant<>`, so this will actually + // persistently store a copy of all possible requests even if + // we're only interested in the process data, since that's the + // only object where allocations can happen. The other objects + // we're storing here are very small, so the extra wasted memory + // shouldn't matter much. + thread_local std::optional persistent_object( + persistent_buffers ? std::make_optional() + : std::nullopt); + auto request = persistent_buffers ? read_object(socket, *persistent_object,