From 0f768e1c1897ba489080b805a75f453717a8d4d0 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 30 Mar 2018 10:43:46 -0400 Subject: [PATCH] Fix SDL_GameControllerButtonBind layout --- src/SDL2.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index 205bcb9..a061405 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -5282,19 +5282,23 @@ namespace SDL2 public int hat_mask; } - /* This struct has a union in it, hence the Explicit layout. */ + // FIXME: I'd rather this somehow be private... [StructLayout(LayoutKind.Explicit)] + public struct INTERNAL_GameControllerButtonBind_union + { + [FieldOffset(0)] + public int button; + [FieldOffset(0)] + public int axis; + [FieldOffset(0)] + public INTERNAL_GameControllerButtonBind_hat hat; + } + + [StructLayout(LayoutKind.Sequential)] public struct SDL_GameControllerButtonBind { - /* Note: enum size is 4 bytes. */ - [FieldOffset(0)] public SDL_GameControllerBindType bindType; - [FieldOffset(4)] - public int button; - [FieldOffset(4)] - public int axis; - [FieldOffset(4)] - public INTERNAL_GameControllerButtonBind_hat hat; + public INTERNAL_GameControllerButtonBind_union value; } [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMapping", CallingConvention = CallingConvention.Cdecl)]