From beabcda66f16f79448459bc2c871833dd94574fd Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 2 Oct 2022 22:54:16 +0200 Subject: [PATCH] Make YaProcessData safe against moves Won't be an issue, but this won't cost any noticeable amount of performance so it seems like the right thing to do. --- .../serialization/vst3/process-data.cpp | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/common/serialization/vst3/process-data.cpp b/src/common/serialization/vst3/process-data.cpp index 8cada8fd..26d2ce41 100644 --- a/src/common/serialization/vst3/process-data.cpp +++ b/src/common/serialization/vst3/process-data.cpp @@ -19,20 +19,8 @@ #include "../../utils.h" YaProcessData::YaProcessData() noexcept - // This response object acts as an optimization. It stores pointers to the - // original fields in our objects, so we can both only serialize those - // fields when sending the response from the Wine side. This lets us avoid - // allocations by not having to copy or move the data. On the plugin side we - // need to be careful to deserialize into an existing - // `YaAudioProcessor::ProcessResponse` object with a response object that - // belongs to an actual process data object, because with these changes it's - // no longer possible to deserialize those results into a new ad-hoc created - // object. - : response_object_{.outputs = &outputs_, - .output_parameter_changes = &output_parameter_changes_, - .output_events = &output_events_}, - // This needs to be zero initialized so we can safely call - // `create_response()` on the plugin side + : // This needs to be zero initialized so we can safely call + // `create_response()` on the plugin side reconstructed_process_data_() {} void YaProcessData::repopulate(const Steinberg::Vst::ProcessData& process_data, @@ -196,8 +184,19 @@ Steinberg::Vst::ProcessData& YaProcessData::reconstruct( } YaProcessData::Response& YaProcessData::create_response() noexcept { - // NOTE: We return an object that only contains references to these original - // fields to avoid any copies or moves + // This response object acts as an optimization. It stores pointers to the + // original fields in our objects, so we can both only serialize those + // fields when sending the response from the Wine side. This lets us avoid + // allocations by not having to copy or move the data. On the plugin side we + // need to be careful to deserialize into an existing + // `YaAudioProcessor::ProcessResponse` object with a response object that + // belongs to an actual process data object, because with these changes it's + // no longer possible to deserialize those results into a new ad-hoc created + // object. + response_object_.outputs = &outputs_; + response_object_.output_parameter_changes = &output_parameter_changes_; + response_object_.output_events = &output_events_; + return response_object_; }