Skip to content

Commit

Permalink
[SDL] Workaround for a Mono crash in SDL.JoystickGetGUID
Browse files Browse the repository at this point in the history
It appears that Mono 3.4.0 fails to marshal SDL_JoystickGUID
correctly when used as a return value. Changing the fixed buffer
to a couple of long fields allows the struct to be marshalled
correctly.
  • Loading branch information
thefiddler committed Aug 9, 2014
1 parent 645baea commit 5444c0c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Source/OpenTK/Platform/SDL2/Sdl2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,21 +1527,22 @@ struct JoyHatEvent

struct JoystickGuid
{
unsafe fixed byte data[16];
long data0;
long data1;

public Guid ToGuid()
{
byte[] bytes = new byte[16];
byte[] data = new byte[16];

unsafe
{
fixed (byte* pdata = data)
fixed (JoystickGuid* pdata = &this)
{
Marshal.Copy(new IntPtr(pdata), bytes, 0, bytes.Length);
Marshal.Copy(new IntPtr(pdata), data, 0, data.Length);
}
}

return new Guid(bytes);
return new Guid(data);
}
}

Expand Down

0 comments on commit 5444c0c

Please sign in to comment.