From 9e7cfdd8806be9190fedbb361020b10c71db3cf5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 9 Oct 2020 20:58:43 +0200 Subject: [PATCH] VST3: use read-only substream to restore state --- libs/ardour/vst3_plugin.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index c4476fa659..76791755fa 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -2214,10 +2214,15 @@ VST3PI::load_state (RAMStream& stream) continue; } if (is_equal_ID (i->_id, Vst::getChunkID (Vst::kComponentState))) { - tresult res = _component->setState(&stream); + ROMStream s (stream, i->_offset, i->_size); + tresult res = _component->setState(&s); + tresult re2 = res; - stream.seek (i->_offset, IBStream::kIBSeekSet, &seek_result); - tresult re2 = _controller->setComponentState(&stream); + if (FUnknownPtr (_component) == 0) { + /* only if component and controller are not identical */ + s.seek (0, IBStream::kIBSeekSet, NULL); + re2 = _controller->setComponentState(&s); + } if (!(re2 == kResultOk || re2 == kNotImplemented || res == kResultOk || res == kNotImplemented)) { #ifndef NDEBUG @@ -2227,7 +2232,8 @@ VST3PI::load_state (RAMStream& stream) } } else if (is_equal_ID (i->_id, Vst::getChunkID (Vst::kControllerState))) { - tresult res = _controller->setState (&stream); + ROMStream s (stream, i->_offset, i->_size); + tresult res = _controller->setState (&s); if (!(res == kResultOk || res == kNotImplemented)) { #ifndef NDEBUG std::cerr << "VST3: failed to restore controller state\n"; @@ -2277,10 +2283,13 @@ VST3PI::save_state (RAMStream& stream) entries.push_back (c); } - c.start_chunk (getChunkID (Vst::kControllerState), stream); - if (_controller->getState (&stream) == kResultTrue) { - c.end_chunk (stream); - entries.push_back (c); + if (FUnknownPtr (_component) == 0) { + /* only if component and controller are not identical */ + c.start_chunk (getChunkID (Vst::kControllerState), stream); + if (_controller->getState (&stream) == kResultTrue) { + c.end_chunk (stream); + entries.push_back (c); + } } /* update header */