mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

[Bug Report / C#] Suspected bug list of MjBindings.cs

Open kshfire opened this issue 1 year ago • 3 comments

At first, thanks to the MjBindings.cs file, it is easy to use in C#. In the meantime, I think there seem to be some bugs in the MjBindings.cs file. The suspected bugs found are as follows (please check it)

[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.LPStr)] public static unsafe extern string mj_id2name(mjModel_* m, int type, int id);

=> I failed to use "mj_id2name" method, so I modified it as follows:

[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] public static unsafe extern IntPtr mj_id2name(mjModel_* m, int type, int id);

If string return is still OK, please let me know a sample code if possible. :)

//------------------------------------------------------------------------------------

[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] public static unsafe extern mjuiThemeSpacing_* mjui_themeSpacing(int ind);

[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] public static unsafe extern mjuiThemeColor_* mjui_themeColor(int ind);

Looking at the original C code, the return types are not a pointer. Thus, these codes were modified as follows.

[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] public static unsafe extern mjuiThemeSpacing_ mjui_themeSpacing(int ind);

[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] public static unsafe extern mjuiThemeColor_ mjui_themeColor(int ind);

I think it's a bug caused by a typo.

kshfire avatar May 10 '24 01:05 kshfire

cc @Balint-H

yuvaltassa avatar May 10 '24 07:05 yuvaltassa

I remember using id2name at some point in the past, but that it was quite finnicky, I'll have a look into it.

Balint-H avatar May 13 '24 07:05 Balint-H

I remember using id2name at some point in the past, but that it was quite finnicky, I'll have a look into it.

Below is the method I'm using (By googling) var ptr = mj_id2name(m_, (int)mjtObj.mjOBJ_BODY, selbody); string variable = Marshal.PtrToStringAnsi(ptr);

It would be best if we could use the return type of id2name as a C# string (if possible). :)

kshfire avatar May 13 '24 09:05 kshfire