Skip to content

Multiple problems when using with Unity/MacOS #8

@staszain

Description

@staszain

Hi, I'm evaluating this library for some time now in Unity. I managed to import it into the project with some issues (for some reason it doesn't load the first time you run the game), however it doesn't work out of the box for me. I've compiled the library from 1.1.0 and took the same version of the bindings. Here are the problems I've encountered so far:

  1. client.DispatchCallback(status) is getting called with info structure containing garbage. It looks like there is a problem with marshalling. I was able to fix this with adding "ref" to the StatusCallback declaration:
    public delegate void StatusCallback(ref StatusInfo info, IntPtr context);
    I'm not an expert in c# marshalling and not sure this is a right fix and the system is now working as it supposed to, or is it going to break other platforms.

  2. Once StatusCallback is changed, the structure still seems to be off. It appears that some of the field values are shifted to neighbour fields. I was able to fix this by adding StructLayoutAttribute.Pack = 4 to StatusInfo structure declaration:
    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public struct StatusInfo {
    ...
    as it looks like "connection" variable takes whole 8 bytes instead of 4. Not sure why Unity/Mono has a different default Pack setting, but I think this should fix the problem for Mono and not break other platforms.

  3. Just a suggestion to mention deinitialization procedure, especially if you set a debug callback like described in the "Usage":

Library.Initialize();
NetworkingUtils utils = new NetworkingUtils();
utils.SetDebugCallback(DebugType.Everything, debug);

you absolutely MUST set it to None when you're done:

utils.SetDebugCallback(DebugType.None, null);
Library.Deinitilize();

otherwise Unity will freeze on the next launch (probably because debug callback is now invalid and crashes silently somewhere inside).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions