Error with Image subscriber
Opened this issue · 0 comments
I am having an error with the subscriber to a topic that publishes messages in sensor_msgs/Image format. This error only occurs when I implement it in Hololens 2. In Unity it works correctly. Attached is the Visual Studio console error and the subscriber script:
Exception thrown at 0x00007FFA4055DDA0 in MRTK Hololens Template.exe: Excepción de Microsoft C++: Il2CppExceptionWrapper en la posición de memoria 0x00000003F5DFCA00.
NullReferenceException: Referencia de objeto no establecida a una instancia de un objeto.
en RosSharp.RosBridgeClient.Communicator.GetRosName[T] () [0x00000] en <00000000000000000000000000000000>:0
at RosSharp.RosBridgeClient.Subscriber1[T]..ctor (System.String id, System.String topic, RosSharp.RosBridgeClient.SubscriptionHandler
1[T] subscriptionHandler, RosSharp.RosBridgeClient.Subscription& subscription, System.Int32 throttle_rate, System.Int32 queue_length, System.Int32 fragment_size, System.String compression) [0x00000] in <00000000000000000000000000000000>:0
at RosSharp.RosBridgeClient.RosSocket.Subscribe[T] (System.String topic, RosSharp.RosBridgeClient.SubscriptionHandler1[T] subscriptionHandler, System.Int32 throttle_rate, System.Int32 queue_length, System.Int32 fragment_size, System.String compression) [0x00000] in <00000000000000000000000000000000>:0 at RosSharp.RosBridgeClient.Subscriber
1[T].Start () [0x00000] in <00000000000000000000000000000000>:0
at RosSharp.RosBridgeClient.ImageSubscriber.Start () [0x00000] in <0
Script:
using UnityEngine;
using UnityEngine.UI;
namespace RosSharp.RosBridgeClient
{
[RequireComponent(typeof(RosConnector))]
public class ImageSubscriber : Subscriber<Messages.Sensor.Image>
{
public MeshRenderer meshRenderer;
private Texture2D texture2D;
private byte[] imageData;
private bool isMessageReceived;
public GameObject raw;
private int width, height;
protected override void Start()
{
base.Start();
texture2D = new Texture2D(1, 1);
meshRenderer.material = new Material(Shader.Find("Standard"));
}
private void Update()
{
if (isMessageReceived)
ProcessMessage();
}
protected override void ReceiveMessage(Messages.Sensor.Image Image)
{
width = (int)Image.width; // Ancho de la imagen (número de filas)
height = (int)Image.height;
imageData = Image.data;
isMessageReceived = true;
}
private void ProcessMessage()
{
//texture2D = new Texture2D(width, height, TextureFormat.RGB24, false);
texture2D.LoadImage(imageData);
texture2D.Apply();
meshRenderer.material.SetTexture("_MainTex", texture2D);
raw.GetComponent<RawImage>().texture = texture2D;
isMessageReceived = false;
}
}
}