iPlug2 Forum

Problems with IPlugChunks

Hello everybody!
What is the expected behavior of IPlugChunks? I tried loading it in Reaper but the state was not preserved in the tests I’ve done. I tried saving a preset from the menu and copy-pasting the preset, which usually creates a cloned instance.

did you make sure to Serialize/Unserialize the Params at the end of the Serialize/Unserialize state override functions?

I’m running the example as it is.

The two functions are like this:

bool IPlugChunks::SerializeState(IByteChunk &chunk) const
{
  // serialize the multislider state state before serializing the regular params
  for (int i = 0; i< kNumSteps; i++)
  {
chunk.Put(&mSteps[i]);
  }
  
  return SerializeParams(chunk); // must remember to call SerializeParams at the end
}

// this over-ridden method is called when the host is trying to load the plug-in state and you need to unpack the data into your algorithm
int IPlugChunks::UnserializeState(const IByteChunk &chunk, int startPos)
{
  double v = 0.;
  
  // unserialize the steps state before unserializing the regular params
  for (int i = 0; i< kNumSteps; i++)
  {
startPos = chunk.Get(&v, startPos);
mSteps[i] = v;
  }
  
  // If UI exists
  if(GetUI())
UpdateUIControls();
  
  // must remember to call UnserializeParams at the end
  return UnserializeParams(chunk, startPos);
}

Mmm that’s strange, l haven’t tried copying presets, but so far l haven’t had problems with the state when l load a saved project with the plugins in it. I carried out a quick test on Reaper and it works fine.

Let me try that. My guess is that it should be the same.

Now I tried saving and reopening the project. It makes no difference, the plugin starts from the default state.

did you change in config.h the line #define PLUG_DOES_STATE_CHUNKS from 0 to 1?

Yes, it is set to 1:

#define PLUG_DOES_STATE_CHUNKS 1

I’m just running the example, I didn’t change anything. If you want to test it yourself, here it is

You were right, I got the same problem with the IPlugChunks example, but I think I’ve found the problem. The variable mSteps is defined as a float array in IPlugChunks.h but in the Unserialize function it’s using a double variable to read the data, (causing a mismatch in the number of bytes read)

Change the very fist line inside the UnserializeState function from

double v = 0.;

to

float v = 0.;

and for me at least it works.

1 Like

It also works for me. Well spotted!
Although his kind of error is understandable, how come nobody found out for 9 months? The example should have not worked for everyone who tried it.

Good question!
At least in my case I always start with an IPlugEffect or IPlugInstrument template and only check the other ones for reference but have never compiled them. I suppose Oli may want to take a look at it, but I don’t quite know how to tag him… still, I guess he will read this at some point?

I suspect not many people are checking this example.

Pease make an issue and if possible also a PR on GitHub and we can roll in the fix.

Thanks, this partially fixes it. There seems to be another issue with this example, where the state is sometimes not recalled correctly so the sliders are in slightly different positions on recall. this may be due to the way the multislider data is sent

should be fixed now on master

1 Like

Awesome! Thanks to everyone for helping out