From 51876a024c04f5318bf294ef7adf1cdde72b50de Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 22 Dec 2020 13:54:55 +0100 Subject: [PATCH] Remove null pointer support in setComponentHandler This should be an implementation fault. --- src/common/logging/vst3.cpp | 9 ++--- .../vst3/plugin/edit-controller.h | 10 ++---- .../bridges/vst3-impls/plugin-proxy.cpp | 34 +++++++++---------- src/wine-host/bridges/vst3.cpp | 22 +++++------- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/common/logging/vst3.cpp b/src/common/logging/vst3.cpp index 3fa80143..b259da24 100644 --- a/src/common/logging/vst3.cpp +++ b/src/common/logging/vst3.cpp @@ -209,13 +209,8 @@ bool Vst3Logger::log_request( const YaEditController::SetComponentHandler& request) { return log_request_base(is_host_vst, [&](auto& message) { message << request.instance_id - << ": IEditController::setComponentHandler(handler = "; - if (request.component_handler_proxy_args) { - message << ""; - } else { - message << ""; - } - message << ")"; + << ": IEditController::setComponentHandler(handler = " + ")"; }); } diff --git a/src/common/serialization/vst3/plugin/edit-controller.h b/src/common/serialization/vst3/plugin/edit-controller.h index 24853ac4..799573bd 100644 --- a/src/common/serialization/vst3/plugin/edit-controller.h +++ b/src/common/serialization/vst3/plugin/edit-controller.h @@ -345,18 +345,12 @@ class YaEditController : public Steinberg::Vst::IEditController { native_size_t instance_id; - /** - * Arguments for instantiating the proxy object. Even though it should - * never happen, if the host passed a null pointer to this function - * we'll mimic that as well. - */ - std::optional - component_handler_proxy_args; + Vst3ComponentHandlerProxy::ConstructArgs component_handler_proxy_args; template void serialize(S& s) { s.value8b(instance_id); - s.ext(component_handler_proxy_args, bitsery::ext::StdOptional{}); + s.object(component_handler_proxy_args); } }; diff --git a/src/plugin/bridges/vst3-impls/plugin-proxy.cpp b/src/plugin/bridges/vst3-impls/plugin-proxy.cpp index 91056187..6e6861b3 100644 --- a/src/plugin/bridges/vst3-impls/plugin-proxy.cpp +++ b/src/plugin/bridges/vst3-impls/plugin-proxy.cpp @@ -337,28 +337,26 @@ Vst3PluginProxyImpl::setParamNormalized(Steinberg::Vst::ParamID id, tresult PLUGIN_API Vst3PluginProxyImpl::setComponentHandler( Steinberg::Vst::IComponentHandler* handler) { - // We'll store the pointer for when the plugin later makes a callback to - // this component handler - component_handler = handler; - - // Automatically converted smart pointers for when the plugin performs a - // callback later - host_application = host_context; - - std::optional - component_handler_proxy_args = std::nullopt; if (handler) { - component_handler_proxy_args = Vst3ComponentHandlerProxy::ConstructArgs( - component_handler, instance_id()); + // We'll store the pointer for when the plugin later makes a callback to + // this component handler + component_handler = handler; + + // Automatically converted smart pointers for when the plugin performs a + // callback later + host_application = host_context; + + return bridge.send_message(YaEditController::SetComponentHandler{ + .instance_id = instance_id(), + .component_handler_proxy_args = + Vst3ComponentHandlerProxy::ConstructArgs(component_handler, + instance_id())}); } else { bridge.logger.log( - "Null pointer passed to 'IEditController::setComponentHandler()'"); + "WARNING: Null pointer passed to " + "'IEditController::setComponentHandler()'"); + return Steinberg::kInvalidArgument; } - - return bridge.send_message(YaEditController::SetComponentHandler{ - .instance_id = instance_id(), - .component_handler_proxy_args = - std::move(component_handler_proxy_args)}); } Steinberg::IPlugView* PLUGIN_API diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 50d4c861..0b0e173a 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -255,22 +255,16 @@ void Vst3Bridge::run() { }, [&](YaEditController::SetComponentHandler& request) -> YaEditController::SetComponentHandler::Response { - // If we got passed a component handler, we'll create a proxy - // object and pass that to the initialize function. The lifetime - // of this object is tied to that of the actual plugin object - // we're proxying for. + // We'll create a proxy object for the component handler and + // pass that to the initialize function. The lifetime of this + // object is tied to that of the actual plugin object we're + // proxying for. // TODO: Does this have to be run from the UI thread? Figure out // if it does - if (request.component_handler_proxy_args) { - object_instances[request.instance_id] - .component_handler_proxy = - Steinberg::owned(new Vst3ComponentHandlerProxyImpl( - *this, - std::move(*request.component_handler_proxy_args))); - } else { - object_instances[request.instance_id] - .component_handler_proxy = nullptr; - } + object_instances[request.instance_id].component_handler_proxy = + Steinberg::owned(new Vst3ComponentHandlerProxyImpl( + *this, + std::move(request.component_handler_proxy_args))); return object_instances[request.instance_id] .edit_controller->setComponentHandler(