From cf3a30d024cd351ae81e3f1bf9b8d4b06921cd00 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Thu, 3 Apr 2014 23:19:31 +0200 Subject: [PATCH] [Mac] CGDisplayBounds signature now matches Mac ABI This resolves a crash in CGDisplayBounds when running through monokick. --- .../Platform/MacOS/Carbon/QuartzDisplayServicesAPI.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/OpenTK/Platform/MacOS/Carbon/QuartzDisplayServicesAPI.cs b/Source/OpenTK/Platform/MacOS/Carbon/QuartzDisplayServicesAPI.cs index 1e38c57..c4aa0ea 100644 --- a/Source/OpenTK/Platform/MacOS/Carbon/QuartzDisplayServicesAPI.cs +++ b/Source/OpenTK/Platform/MacOS/Carbon/QuartzDisplayServicesAPI.cs @@ -69,8 +69,20 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(appServices,EntryPoint="CGMainDisplayID")] internal static extern IntPtr MainDisplayID(); - [DllImport(appServices, EntryPoint = "CGDisplayBounds")] - internal unsafe static extern HIRect DisplayBounds(IntPtr display); + // Note: sizeof(HIRect) == 16, which is larger than 8 bytes. + // The x86 and x64 Mac ABIs pass such structs as pointers in the + // first parameter slot. This is normally handled automatically + // by gcc/clang, but here we have to do it ourselves. + // See "Listing 4" on https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html#//apple_ref/doc/uid/TP40002492-SW3 + internal unsafe static HIRect DisplayBounds(IntPtr display) + { + HIRect rect; + DisplayBounds(out rect, display); + return rect; + } + + [DllImport(appServices, EntryPoint = "CGDisplayBounds")] + unsafe static extern void DisplayBounds(out HIRect rect, IntPtr display); [DllImport(appServices,EntryPoint="CGDisplayPixelsWide")] internal static extern int DisplayPixelsWide(IntPtr display); -- 2.7.4