Skip to content

Built Unity Player on Windows fails to load ROS2 as it thinks we are on a Mac #70

Description

@jpimmt

Getting this error when I run a built player on Windows using Ros2ForUnity e.g. AWSIM

UnsatisfiedLinkError: librcl.dylib
  at ROS2.DllLoadUtilsMacOSX.LoadLibraryNoSuffix (System.String fileName) [0x0002b] in <a2a919017a70434a94efb7733ae66da5>:0 
  at ROS2.NativeRcl..cctor () [0x0000a] in <680ec49a722e41208641c44cc0cd291a>:0 
Rethrow as TypeInitializationException: The type initializer for 'ROS2.NativeRcl' threw an exception.
  at ROS2.ROS2ForUnity..ctor () [0x00091] in <078acfce5b514a38a96f12e8379c1a42>:0 
  at ROS2.ROS2UnityCore..ctor () [0x00038] in <078acfce5b514a38a96f12e8379c1a42>:0 
  at Awsim.Common.AwsimRos2Node.Initialize () [0x0000f] in <078acfce5b514a38a96f12e8379c1a42>:0 
  at Awsim.Scene.AutowareSimulationDemo.AutowareSimulationDemo.Start () [0x0004f] in <078acfce5b514a38a96f12e8379c1a42>:0 

Turns out the mechanism to detect what platform we are running on is the issue. It relies on PInvoke on system specific libraries.
https://github.com/RobotecAI/ros2cs/blob/develop/src/ros2cs/ros2cs_common/DllLoadUtils.cs#L113

 private static bool IsMacOSX () {
      try {
        IntPtr ptr = dlopen_macosx ("libdl.dylib", RTLD_NOW);
        dlclose_macosx (ptr);
        return true;
      } catch (TypeLoadException) {
        return false;
      }
    }

The linked code doesn't throw a TypeLoadException on my machine because I have Strawberry Perl installed which has a copy of libdl.dll in C:\Strawberry\c\bin. In a player environment unity ignores the *.dylib extension and loads the dll version instead.

The fix would be a more robust way of detecting platform support relying more on preprocessor defines. For now I'll just remove Perl from my Path environment variable when I run AWSIM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions