EricVoll / ros-sharp

ROS# is a set of open source software libraries and tools in C# for communicating with ROS from .NET applications, in particular Unity3D
Apache License 2.0
36 stars 7 forks source link

ArgumentNullException: Value cannot be null. Parameter name: key #12

Closed Rive4 closed 3 years ago

Rive4 commented 3 years ago

I found a bug!

Hello, I was created a publisher which publishes Vector3 with the following code.

using RosSharp.RosBridgeClient;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVerticesPublisher : UnityPublisher<RosSharp.RosBridgeClient.MessageTypes.Geometry.Vector3>
{

    private RosSharp.RosBridgeClient.MessageTypes.Geometry.Vector3 message;
    public string FrameId = "Unity";
    public List<UnityEngine.Vector3> verticesList;

    protected override void Start()
    {
        base.Start();
        InitializeMessage();
    }

    private void FixedUpdate()
    {
        UpdateMessage();
    }

    private void InitializeMessage()
    {
        verticesList = new List<Vector3>();
        message = new RosSharp.RosBridgeClient.MessageTypes.Geometry.Vector3();
    }

    private void UpdateMessage()
    {
        if (verticesList.Count != 0)
        {
            message = parseUnityVector3toROSVector3(verticesList[0]);
            print("PUBLISHING... : " + verticesList[0].ToString());
            verticesList.RemoveAt(0);
            print("Publish(message);");
            Publish(message);
            print("verticesList.Clear();");
        }

    }

    private RosSharp.RosBridgeClient.MessageTypes.Geometry.Vector3 parseUnityVector3toROSVector3(UnityEngine.Vector3 vector3)
    {
        return new RosSharp.RosBridgeClient.MessageTypes.Geometry.Vector3(vector3.z, -vector3.x, vector3.y);
    }
}

The 'verticesList' is filled in another script but I can confirm that it does well, because when I print verticesList[0].ToString() it works well.

So, when I compile and use the application for Hololens 2, after running the routine which publishes these messages, I find the following error in the UnityPlayer.log file in HL2:

Parameter name: key
  at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x00000] in <00000000000000000000000000000000>:0 
  at RosSharp.RosBridgeClient.RosSocket.Publish (System.String id, RosSharp.RosBridgeClient.Message message) [0x00000] in <00000000000000000000000000000000>:0 
  at RosSharp.RosBridgeClient.UnityPublisher`1[T].Publish (T message) [0x00000] in <00000000000000000000000000000000>:0 
  at MeshVerticesPublisher.UpdateMessage () [0x00000] in <00000000000000000000000000000000>:0 

(Filename: currently not available on il2cpp Line: -1)

This error is happening while it is trying to publish the message (Publish(message);) What I see the most strange is that the rest of messages I created are working perfectly and have more complex.

EricVoll commented 3 years ago

Hi @Rive4 I missed your issue...

Are you still experiencing problems or were you able to solve the problem?

EricVoll commented 3 years ago

btw: There is a specific message type in ROS for meshes: here

Rive4 commented 3 years ago

Hi @EricVoll ,

Hi @Rive4 I missed your issue...

Are you still experiencing problems or were you able to solve the problem?

Finally what I did was to send each vertex one by one instead of in a list. I know that it is not the best way to do it but at least I receive the messages correctly in ROS.

btw: There is a specific message type in ROS for meshes: here

Thank you for the mesh message reference, I did not know about it before.

EricVoll commented 3 years ago

ok. Still not sure why it failed though. I didn't run your code yet, but it looks like the publisher was not finished advertising at the time the first message was sent.

Advertising usually takes a bit. So you might want to wait with publishing until publicationId is set.

EricVoll commented 3 years ago

Did the code also fail when running it in Editor mode?

Rive4 commented 3 years ago

I didn't test it in Editor mode. I use to compile the solution so I can connect the PC (in Ubuntu) with the developed program.

EricVoll commented 3 years ago

In any case, this seems to not be fork-related and should also happen using the normal ros-sharp fork. If I remember correctly, I had the issue once as well and either changed to the correct message, created my own "array message" where the whole list could be sent in one go, or only published one message per update cycle. If I remember correctly, ros-sharp has issues to publish multiple messages from one publisher in one update cycle.