Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Commit

Permalink
Fix offset when sending state to LV2 UI
Browse files Browse the repository at this point in the history
  • Loading branch information
pdesaulniers committed Mar 29, 2019
1 parent c1eb15d commit 8080933
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions distrho/src/DistrhoPluginLV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,24 +635,27 @@ class PluginLv2
// set msg size (key + value + separator + 2x null terminator)
const size_t msgSize(key.length()+value.length()+3);

if (sizeof(LV2_Atom_Event) + msgSize > capacity - offset)
if (sizeof(LV2_Atom_Event) + msgSize > capacity - fEventsOutData.offset)
{
d_stdout("Sending key '%s' to UI failed, out of space", key.buffer());
break;
}

// reserve msg space
// FIXME create a large enough buffer beforehand
char msgBuf[msgSize];
std::memset(msgBuf, 0, msgSize);

// write key and value in atom bufer
std::memcpy(msgBuf, key.buffer(), key.length());
std::memcpy(msgBuf+(key.length()+1), value.buffer(), value.length());
std::memcpy(msgBuf, key.buffer(), key.length()+1);
std::memcpy(msgBuf+(key.length()+1), value.buffer(), value.length()+1);

// put data
aev = (LV2_Atom_Event*)(LV2_ATOM_CONTENTS(LV2_Atom_Sequence, fEventsOutData.port) + offset);
aev = (LV2_Atom_Event*)(LV2_ATOM_CONTENTS(LV2_Atom_Sequence, fEventsOutData.port) + fEventsOutData.offset);
aev->time.frames = 0;
aev->body.type = fURIDs.distrhoState;
aev->body.size = msgSize;
std::memcpy(LV2_ATOM_BODY(&aev->body), msgBuf, msgSize-1);
std::memcpy(LV2_ATOM_BODY(&aev->body), msgBuf, msgSize);

fEventsOutData.growBy(lv2_atom_pad_size(sizeof(LV2_Atom_Event) + msgSize));

Expand Down

0 comments on commit 8080933

Please sign in to comment.