RobotecAI/ros2-for-unity

Segmentation fault when creating ROS2 node with Cyclone DDS

ynyBonfennil opened this issue · 0 comments

Describe the bug
When using Cyclone DDS as the DDS, creating ROS2 node with Ros2ForUnity fails with segmentaion fault.

Environment

  • OS: Ubuntu 22.04 Desktop (amd64)
  • ros2 distro: humble (ros-humble-desktop 0.10.0-1jammy.20230920.004932)
  • ros2-for-unity-version: the latest devel branch (commit id a195bf6)
  • ros2 dds middleware: cyclonedds (ros-humble-rmw-cyclonedds-cpp 1.3.4-1jammy.20230919.205940)
  • ros2 environment setup: single pc
  • Unity (2021.3.10f1)

To Reproduce
Steps to reproduce the behavior:

  1. Enable Cyclone DDS by the official documentation
  2. Build Ros2ForUnity by following README.md
  3. Create new unity project
  4. Create the following C# script and attach to a gameobject in a scene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ROS2;

public class SampleScript : MonoBehaviour
{
    private ROS2UnityCore ros2Unity;
    private ROS2Node ros2Node;

    void Awake() {
        ros2Unity = new ROS2UnityCore();
    }

    // Start is called before the first frame update
    void Start()
    {
        if (ros2Unity.Ok()) {
            ros2Node = ros2Unity.CreateNode("unity_ros2_node");
        }

    }
}
  1. Run Unity Editor
  2. Unity Editor crashes

Screenshot from 2023-10-03 14-02-06

~/.config/unity3d/Editor.log's last few lines are as follow

Loaded scene 'Temp/__Backupscenes/0.backup'
	Deserialize:            0.470 ms
	Integration:            75.618 ms
	Integration of assets:  0.005 ms
	Thread Wait Time:       0.025 ms
	Total Operation Time:   76.118 ms
Caught fatal signal - signo:11 code:1 errno:0 addr:0x560e00000001
Obtained 10 stack frames.
#0  0x007fce5d242520 in __sigaction
#1  0x007fce5d39d9bd in __nss_database_lookup
#2  0x007fcc7c0e321d in ddsrt_strdup
#3  0x007fcc7c0cf082 in dds_create_topic_impl
#4  0x007fcc7c0cf68c in dds_create_topic_sertype
#5  0x007fcc7c15aed0 in rmw_deserialize
#6  0x007fcc7c15b277 in rmw_deserialize
#7  0x007fcc7c15cf3c in rmw_create_node
#8  0x007fcd100f920a in rcl_node_init
#9  0x0000004231b058 in (wrapper managed-to-native) object:wrapper_native_0x7fcd100f8da0 (ROS2.rcl_node_t&,string,string,ROS2.rcl_context_t&,intptr)
Launching bug reporter
Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created.

Expected behavior
A node "unity_ros2_node" is created

Additional context

It seems like ros2cs's this line is causing the error. The error log says ddsrt_strdup is in the stack frames and it is from cyclonedds's this line. I don't really know how to debug the middleware level issue, so I don't know any further.

When switching to fastdds, it works properly. It happens only on cyclonedds. It may be related to cyclonedds's latest update or something.