Hello guys,
I am new in JUCE and I found myself stuck when I am trying to load preset.
Whenever I am trying to load a preset I am having a message “Thread 1: EXC_BAD_ACCESS(code=EXC_I386_GPFTL)”, and that is on the LinkedListPointer& function. It shows that the juce::XMLElement::XMLAttributeNode* is NULL. Therefore I guess it cannot return the attributes.size.
The code I am using in the getStateInformation is:
` XmlElement preset (“KAP_StateInfo”);
XmlElement* presetBody = new XmlElement ("KAP_Preset");
mPresetManager->getXmlForPreset(presetBody);
preset.addChildElement(presetBody);
copyXmlToBinary(preset, destData); `
I have also made a Preset manager class where I have all the function to get xml from preset or load and make new preset.
The getXmlForPreset function code is:
void KAPPresetManager::getXmlForPreset (XmlElement* inElement)
{
auto& parameters = mProcessor->getParameters();
for (int i = 0; i <parameters.size(); i++)
{
AudioProcessorParameterWithID* parameter =
(AudioProcessorParameterWithID*)parameters.getUnchecked(i);
inElement->setAttribute(parameter->paramID,
parameter->getValue());
}
}
In my understanding everything is ok so far. Isn’t it?
Then the setStateInformation function code is:
//XmlElement* xmlState = getXmlFromBinary(data, sizeInBytes).get();
std::unique_ptr<XmlElement> xmlState;
xmlState.reset(getXmlFromBinary(data, sizeInBytes).get());
if(xmlState.get() != nullptr)
{
forEachXmlChildElement(*xmlState, subChild)
{
mPresetManager->loadPresetForXml(subChild); // (Thread 1: EXC_BAD_ACCESS(code=EXC_I386_GPFTL) )
}
} else
jassertfalse;
And the load preset for xml function code is:
void KAPPresetManager::loadPresetForXml (XmlElement* inElement)
{
mCurrentPresetXml = inElement;
auto& _parameters = mProcessor->getParameters();
for (int i = 0; i < mCurrentPresetXml->getNumAttributes(); i++) // (Thread 1: EXC_BAD_ACCESS(code=EXC_I386_GPFTL) )
{
const String paramId = mCurrentPresetXml->getAttributeName(i);
const float value = mCurrentPresetXml->getDoubleAttribute(paramId);
for (int j = 0; j < _parameters.size(); j++)
{
AudioProcessorParameterWithID* parameter =
(AudioProcessorParameterWithID*)_parameters.getUnchecked(i);
if (paramId == parameter->paramID)
{
parameter->setValueNotifyingHost(value);
}
}
}
}
I cannot understand why is this happening and I cannot find a solution no matter what I have tried. Anyone can help I would really appriciate.

