This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
10 / 10
Oct 2019

Hi, I just downloaded the Orion SDK and was looking to serialize frames. However, the current implementation of Frame.cs in Assets\LeapC\Frame.cs reads:

    public byte[] Serialize
    {
        get
        {
            byte[] ptr = new byte[1];
            ptr[1] = 0;
            return ptr;
        }
    }

Which will cause a IndexOutOfBounds error, and it looks like it will return an empty array.

Is there another way to get serialized data?

  • created

    Feb '16
  • last reply

    Oct '19
  • 9

    replies

  • 4.5k

    views

  • 5

    users

  • 1

    like

Hi Joe, thank you for your reply!

Could you please give me an idea of when this might be implemented?

Probably within the month, but that's just an estimate. I can't make concrete promises.

Hi Joe, thanks again for being so fast!

Okay, it looks like for now I'll have to serialize and deserialize things myself, I'm looking forward to when this is done! By the way the new tracking is really fantastic smile

6 months later

Hello,

is frame serialization implemented? I am getting error
IndexOutOfRangeException: Array index is out of range. Leap.Frame.get_Serialize () (at Assets/LeapC/Frame.cs:109)

Using Orion 3.0 and Unity 5.4

Thanks

No, it is not. However, Frame objects are no longer immutable so implementing serialization on your own is at least possible in this version. In fact default C# serialization might even work.

7 months later

Hi,

I am currently trying to use frame.serialize but i am getting the same error as the guys above. You last posted in September 2016 and at the time of writing this it's now 6th May 2017, are we ever going to see frame.serialize implemented as i desperately need it ? I am not aware of many, if any developments with the orion sdk since September 2016, have you abandoned it ?

If you have not yet or have no intention of implementing frame serialization, then can you at least give me some guidance on implementing my own serialization.

2 years later

Hi Guys,

I was getting my head around this issue the last couple days. Please find my implementation below.
To be considered:

  1. The c# binary formatter only works in the same appDomain (assambly), still need to get my head around that. This means the deserialization can only be done in the same program.
  2. The "InteractionBox" struc needs to be made serializable as well.

My serialization code is:

    public byte[] Serialize
    {
        get
        {
            BinaryFormatter bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
                bf.Serialize(ms, this);
                return ms.ToArray();
            }
        }
    }

My code for deserialization:

    public void Deserialize(byte[] arg)
    {
        using (var ms = new MemoryStream())
        {
            BinaryFormatter bf = new BinaryFormatter();
            ms.Write(arg, 0, arg.Length);
            ms.Seek(0, SeekOrigin.Begin);
            Frame objArray = (Frame)bf.Deserialize(ms);
            this.Id = objArray.Id;
            this.Timestamp = objArray.Timestamp;
            this.CurrentFramesPerSecond = objArray.CurrentFramesPerSecond;
            this.InteractionBox = objArray.InteractionBox;
            this.Hands = objArray.Hands;
        }

    }

My code to get the Lenght:

    public int SerializeLength
    {
        get
        {
            BinaryFormatter bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
                bf.Serialize(ms, this);
                return ms.ToArray().Length;
            }
        }
    }

Part of the "InteractionBox.cs":

[System.Serializable]
public struct InteractionBox{...}

Also to create your own *.dll (Leap.dll in my case instead of the csharp.dll) in order to use the frame object serialization across several applications.

csc /t:library /out:Leap.dll LeapC.cs Arm.cs Bone.cs CircularObjectBuffer.cs ClockCorrelator.cs Config.cs Connection.cs Controller.cs CopyFromLeapCExtensions.cs CopyFromOtherExtensions.cs CSharpExtensions.cs Device.cs DeviceList.cs DistortionData.cs DistortionDictionary.cs Events.cs FailedDevice.cs FailedDeviceList.cs Finger.cs Frame.cs Hand.cs IController.cs Image.cs ImageData.cs ImageFuture.cs InteractionBox.cs LeapQuaternion.cs LeapTransform.cs Logger.cs Matrix.cs MessageSeverity.cs ObjectPool.cs PendingImages.cs PooledObject.cs StructMarshal.cs TimeBracket.cs TransformExtensions.cs Vector.cs

You still need to make the copy reference in your postbuild to the LeapC.dll from the x86/x64 SDK folder

Hope that helps,

Cheers Sedowan