From cd7423ae342cd2c4e7e36a8b8d838024cf9c9587 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 20 Jul 2021 12:23:10 +0200 Subject: [PATCH] Use ref when passing structs by pointer through P/Invoke. This fixes positions and angles not being updated correctly in 32-bit builds. This was not a problem in 64-bit mode (probably because an entire vec3_t fits into a single register and the call is optimized as such) but it is in 32-bit mode. --- Assets/Scripts/Modules/GameModule.Interop.cs | 4 ++-- Assets/Scripts/Modules/RenderModule.Interop.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Modules/GameModule.Interop.cs b/Assets/Scripts/Modules/GameModule.Interop.cs index fa7106a..3e72b1b 100644 --- a/Assets/Scripts/Modules/GameModule.Interop.cs +++ b/Assets/Scripts/Modules/GameModule.Interop.cs @@ -48,10 +48,10 @@ public partial class GameModule : CallbackHandler } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void GameSetEntityTransformCallback(IntPtr target, int entityNum, QVec3 origin, QVec3 angles); + private delegate void GameSetEntityTransformCallback(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles); [MonoPInvokeCallback(typeof(GameSetEntityTransformCallback))] - private static void Callback_GameSetEntityTransform(IntPtr target, int entityNum, QVec3 origin, QVec3 angles) + private static void Callback_GameSetEntityTransform(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles) { GetSelf(target).SetEntityTransform(entityNum, origin, angles); } diff --git a/Assets/Scripts/Modules/RenderModule.Interop.cs b/Assets/Scripts/Modules/RenderModule.Interop.cs index a02deb5..2af570a 100644 --- a/Assets/Scripts/Modules/RenderModule.Interop.cs +++ b/Assets/Scripts/Modules/RenderModule.Interop.cs @@ -124,10 +124,10 @@ public partial class RenderModule: CallbackHandler } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void SetupViewCallback(IntPtr target, QVec3 origin, QVec3 angles, QLeaf viewLeaf); + private delegate void SetupViewCallback(IntPtr target, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf); [MonoPInvokeCallback(typeof(SetupViewCallback))] - private static void Callback_SetupView(IntPtr target, QVec3 origin, QVec3 angles, QLeaf viewLeaf) + private static void Callback_SetupView(IntPtr target, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf) { GetSelf(target).SetupView(origin, angles, viewLeaf); }