Cross-Platform plugin state saving->restoring

Hello!
We have a cross-platform plugin.
With an host we can save the state on iPadOS and restore it on macOS, but when RestoreState is called it return before call setStateInformation

            if (err != noErr)
                return err;

because err is equal to -10851 (kAudioUnitErr_InvalidPropertyValue).

We have checked the plist with the saved state and We noticed that the “version” tag is different:
for iPad is 1
for macOS is 0

So the problem is on this check:

// first step -> check the saved version in the data ref
// at this point we're only dealing with version==0
	CFNumberRef cfnum = reinterpret_cast<CFNumberRef>(CFDictionaryGetValue (dict, kVersionString));
	if (cfnum == NULL) return kAudioUnitErr_InvalidPropertyValue;
	SInt32 value;
	CFNumberGetValue (cfnum, kCFNumberSInt32Type, &value);
	if (value != kCurrentSavedStateVersion) return kAudioUnitErr_InvalidPropertyValue;

I’m asking why the #define kCurrentSavedStateVersion is set to 0
Vice versa saving from macOS and restore on iPadOS is working.
I can solve this problem setting kCurrentSavedStateVersion to 1.

I also ran into this bug in a previous job, trying to port a non-JUCE plugin to JUCE and running into incompatibility with the older presets because of this exact problem.

Would be just great if the #define could be externally defined by the build system instead of hard coded?

Likewise here, the addition of an external #define or just wrapping it in an #ifndef would be a massive help.

2 Likes