Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity crashes when receiving map message #104

Open
jvmoraiscb opened this issue Apr 24, 2024 · 0 comments
Open

Unity crashes when receiving map message #104

jvmoraiscb opened this issue Apr 24, 2024 · 0 comments

Comments

@jvmoraiscb
Copy link

I have the code below that receives a message of type OccupancyGrid and for now, it does nothing. I have published some "fake" maps that are very small (50x50) and I can receive the message normally. However, when receiving an actual map (e.g., 300x300), Unity crashes instantly. The code is as follows:

using UnityEngine;
using ROS2;

public class MapSubscriber : MonoBehaviour{
    [Header("Map Settings")]
    [SerializeField] private string nodeName = "MapSub_Unity";
    [SerializeField] private string topicName = "map";

    // [Header("CmdVel Dependencies")]
    // [SerializeField] private GameObject wallPrefab;

    private ROS2UnityComponent ros2Unity;
    private ROS2Node ros2Node;
    private ISubscription<nav_msgs.msg.OccupancyGrid> sub;

    private void Start(){
        ros2Unity = GetComponent<ROS2UnityComponent>();
    }

    private void Update(){
        if(!ros2Unity.Ok()) return;
        if(ros2Node == null){
            ros2Node = ros2Unity.CreateNode(nodeName);
            sub = ros2Node.CreateSubscription<nav_msgs.msg.OccupancyGrid>(topicName, msg => MapCallback(msg));
        }
    }

    private void MapCallback(nav_msgs.msg.OccupancyGrid msg){
        Debug.Log(msg.Info.Height + " - " + msg.Info.Width);
    }
}

Is the fact that Unity cannot receive this message some limitation of the library itself or is there an additional step that I haven't taken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant