XmlElement Error 'Bad Thread'

So total beginner here with C++ and JUCE. I have been following a Kadenze course to help walk me through how to develop an audio plugin. Unfortunately this course is pretty outdated and I’ve had to teach myself a good chunk of it. I am getting error when I try to write and restore my parameters from the memory block. Below is what my current SetState and GetState functions look like.

I have a separate .h and .cpp files to handle the get preset and load preset for XML
Screen Shot 2021-03-29 at 3.59.19 PM

So my issue is when I try to execute my code it fails when trying to restore the XML. I receive the following error I am not sure what it means.

Can anyone advise on some possible solutions for this? I did find another thread that may address the issue, but as a beginner I haven’t been able to figure out the steps to resolve my issue.


Looks like you’ve got a double deletion going on in getStateInformation(). This line is the culprit:

preset.addChildElement (presetBody.get());

The XmlElement class automatically deletes child nodes when their parent object is deleted, so you have to transfer ownership of any child nodes that are added. Since you’re using a unique_ptr, you can do this by using release() instead of get() in the addChildElement() call:

preset.addChildElement (presetBody.release());
1 Like

Thanks a ton

I was actually able to resolve it by not using presetbody as a unique pointer but instead

XmlElement* presetBody = new XmlElement(“KAP_Preset”);

I think this resolved the same issue you mentioned in a different way.

I was not familiar with the .release() call though I will look into that for future use.

Thank you!