Hi there,
I’m trying to seralize/deserialize a value tree but I’ve got as problem during deserialization.
Here is my serialization code:
if (fileToSerializeTo.existsAsFile())
{
fileToSerializeTo.deleteFile();
}
FileOutputStream fos(fileToSerializeTo);
jassert(!fos.failedToOpen());
mAssetsTree.writeToStream(fos);
fos.flush();
#ifdef JUCE_DEBUG
File debugLog(File::getCurrentWorkingDirectory().getFullPathName() + "\\debug.txt");
debugLog.deleteFile();
FileOutputStream debugStream(debugLog);
debugStream.writeString(mAssetsTree.toXmlString());
#endif
If I check my debug log I have :
<Assets>
<Asset Hash="A" Thumbnail="A" Name="My way" Extension="Wav"/>
<Asset Hash="B" Thumbnail="A" Name="MP3" Extension=""/>
<Asset Hash="C" Thumbnail="A" Name="Supeflip, vite" Extension="Flac"/>
</Assets>
So it looks very good.
Now, my deserialization code
jassert(fileToDeserializeFrom.existsAsFile());
DBG(fileToDeserializeFrom.getFullPathName());
FileInputStream fis(fileToDeserializeFrom);
jassert(!fis.failedToOpen());
mAssetsTree.readFromStream(fis);
for (int pos = 0; pos < mAssetsTree.getNumChildren(); pos++)
{
// do stuff
}
My problem is that it never enters the loop, so I checked what happens in readFromStream(fis) and there is some code
const int numProps = input.readCompressedInt();
where numprops=0 !
Just before, there is :
const String type (input.readString());
and type is Assets so it can read the value tree !
I triple checked and I read and write to the same file.
The contents of the binary file are :
AssetsAsset Hash A Thumbnail A Name My way Extension Wav Asset Hash B Thumbnail A Name MP3 Extension Asset Hash C Thumbnail A Name Supeflip, vite Extension Flac
So it looks ok. I really don’t understand what’s happening here.

