Causes of errors in reading plugin data?


#1

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?


(Dale Fugier) #2

Hi @Max_Eskin,

Are you working in C++ or .NET?

Are you writing user text or do you have a custom UserData class?

We might need to see some code.

– Dale


#3

.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
        }

(Dale Fugier) #4

Hi @Max_Eskin,

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.

– Dale