I’m seeing an error reading from the plugin’s binary archive. Normally my code works but for this document it doesn’t. I am storing the data as a string in YAML format. The writer does not complain and the write error flag is false.
But when I go to read the file, I get an exception “ReadString failed”. I found the method Dump3dmChunk which returns the code 2949165, and the textlog I pass to Dump3dmChunk says “6975168: 002D002D unknown tcode: length = 22236566110666797 bytes ** ERROR near offset 6975180 ** EndRead3dmChunk() failed.”
The length of the string I am writing in this case is 51171414 bytes. Is this too long? Or are there any special characters I should be looking out for?
.NET. I’m using the ReadDocument and WriteDocument methods in the plugin class.
E.g.
protected override void WriteDocument(RhinoDoc doc, BinaryArchiveWriter archive, FileWriteOptions options) {
// Add string data to stringWriter
archive.WriteString(stringWriter.ToString());
}
and
protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options) {
if (options.ImportMode)
return;
var configString = archive.ReadString();
// Do something with the string
}
I’ll probably need your plug-in and the file, in question, to determine the real problem. But this troubles me:
if (options.ImportMode)
return;
When asked to read your plug-in’s user data, you should always do so, even if you choose later not to use the data you’ve read.
Also, your code should be very robust. Does stringWriter return a string, for example.
And, when when writing/reading user data, you should be writing/reading versioning information too. This way, if you need modify your data format, you can do so and still read your older formats.
For example:
protected override void WriteDocument(
RhinoDoc doc,
BinaryArchiveWriter archive,
FileWriteOptions options
)
{
// Write the version of our document data
archive.Write3dmChunkVersion(MAJOR, MINOR);
// TOD: Write the rest of our version MAJOR,MINOR fields here
and
protected override void ReadDocument(
RhinoDoc doc,
BinaryArchiveReader archive,
FileReadOptions options
)
{
archive.Read3dmChunkVersion(out var major, out var minor);
if (MAJOR == major && MINOR == minor)
{
// Always read user data even though you might not use it.
The developer samples repo on GitHub has lots of samples that demonstrate this.