diff --git a/src/ossia-qt/serial/serial_protocol.cpp b/src/ossia-qt/serial/serial_protocol.cpp index d8c53f57ba9..10fd1472fa6 100644 --- a/src/ossia-qt/serial/serial_protocol.cpp +++ b/src/ossia-qt/serial/serial_protocol.cpp @@ -33,6 +33,31 @@ static auto on_open = [] { }; static auto on_close = [] { }; static auto on_fail = [] { }; +namespace +{ +struct serial_osc_queue_callback +{ + serial_protocol& self; + void operator()(const coalescing_queue::coalesced& elts) + { + thread_local std::vector> + osc_messages; + osc_messages.clear(); + + for(auto& [p, v] : elts) + { + auto serial_param = static_cast(p); + if(serial_param->data().osc_address.isEmpty()) + self.do_write(*p, v); + else + osc_messages.emplace_back(serial_param, &v); + } + + self.do_write_osc_bundle(osc_messages); + } +}; +} + struct serial_wrapper_read { serial_wrapper& self; @@ -309,23 +334,10 @@ serial_protocol::serial_protocol( if(res.m_coalesce > 0.) { m_coalesce = res.m_coalesce; - m_queue.callback = [this](const coalescing_queue::coalesced& elts) { - thread_local std::vector< - std::pair> - osc_messages; - osc_messages.clear(); - - for(auto& [p, v] : elts) - { - auto serial_param = static_cast(p); - if(serial_param->data().osc_address.isEmpty()) - do_write(*p, v); - else - osc_messages.emplace_back(serial_param, &v); - } - - do_write_osc_bundle(osc_messages); - }; + + // Separate type due to Windows error: + // error: 'osc_messages' cannot be thread local when declared 'dllexport' + m_queue.callback = serial_osc_queue_callback{*this}; ossia::qt::run_async(m_threadWorker, [this] { m_threadWorker->startTimer(m_coalesce.value(), Qt::PreciseTimer); diff --git a/src/ossia-qt/serial/serial_protocol.hpp b/src/ossia-qt/serial/serial_protocol.hpp index 0f57828d2c8..9a199c14d93 100644 --- a/src/ossia-qt/serial/serial_protocol.hpp +++ b/src/ossia-qt/serial/serial_protocol.hpp @@ -166,7 +166,6 @@ class OSSIA_EXPORT serial_protocol final static serial_parameter_data read_data(const QJSValue& js) { return js; } -private: static serial_protocol_object load_serial_object_from_qml( serial_protocol& proto, const ossia::net::network_context_ptr& ctx, const ossia::net::serial_configuration& cfg); @@ -180,6 +179,8 @@ class OSSIA_EXPORT serial_protocol final std::span> vec); void do_write_osc_impl( const serial_parameter& addr, const ossia::value& v, std::string& str); + +private: QQmlEngine* m_engine{}; QQmlComponent* m_component{};