From 1dfc5db9c2abf00399120bf1675053e81b319dd9 Mon Sep 17 00:00:00 2001 From: Miron Alexandru Date: Mon, 27 May 2024 13:54:02 +0300 Subject: [PATCH] Use UIntPtr for size_t arguments and return values from CSFML --- src/SFML.Audio/Music.cs | 4 ++-- src/SFML.Audio/SoundBuffer.cs | 4 ++-- src/SFML.Audio/SoundRecorder.cs | 14 +++++++------- src/SFML.Graphics/Font.cs | 26 ++++++++++++++++++++++---- src/SFML.Graphics/Image.cs | 4 ++-- src/SFML.Graphics/RenderTexture.cs | 4 ++-- src/SFML.Graphics/RenderWindow.cs | 4 ++-- src/SFML.Graphics/Shader.cs | 24 ++++++++++++------------ src/SFML.Graphics/Shape.cs | 12 ++++++------ src/SFML.Graphics/Text.cs | 4 ++-- src/SFML.Graphics/Texture.cs | 10 +++++----- src/SFML.Graphics/VertexArray.cs | 14 +++++++------- src/SFML.Graphics/VertexBuffer.cs | 8 ++++---- src/SFML.System/Buffer.cs | 4 ++-- src/SFML.Window/VideoMode.cs | 9 +++++---- src/SFML.Window/Vulkan.cs | 6 +++--- 16 files changed, 85 insertions(+), 66 deletions(-) diff --git a/src/SFML.Audio/Music.cs b/src/SFML.Audio/Music.cs index 1772d8c1..34cf08ca 100644 --- a/src/SFML.Audio/Music.cs +++ b/src/SFML.Audio/Music.cs @@ -77,7 +77,7 @@ public Music(byte[] bytes) : GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { - CPointer = sfMusic_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length)); + CPointer = sfMusic_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); } finally { @@ -408,7 +408,7 @@ public TimeSpan(Time offset, Time length) private unsafe static extern IntPtr sfMusic_createFromStream(IntPtr stream); [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfMusic_createFromMemory(IntPtr data, ulong size); + private static extern IntPtr sfMusic_createFromMemory(IntPtr data, UIntPtr size); [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfMusic_destroy(IntPtr MusicStream); diff --git a/src/SFML.Audio/SoundBuffer.cs b/src/SFML.Audio/SoundBuffer.cs index c7c7097a..2685cfa8 100644 --- a/src/SFML.Audio/SoundBuffer.cs +++ b/src/SFML.Audio/SoundBuffer.cs @@ -75,7 +75,7 @@ public SoundBuffer(byte[] bytes) : GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { - CPointer = sfSoundBuffer_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length)); + CPointer = sfSoundBuffer_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); } finally { @@ -224,7 +224,7 @@ protected override void Destroy(bool disposing) private unsafe static extern IntPtr sfSoundBuffer_createFromStream(IntPtr stream); [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfSoundBuffer_createFromMemory(IntPtr data, ulong size); + private unsafe static extern IntPtr sfSoundBuffer_createFromMemory(IntPtr data, UIntPtr size); [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private unsafe static extern IntPtr sfSoundBuffer_createFromSamples(short* Samples, ulong SampleCount, uint ChannelsCount, uint SampleRate); diff --git a/src/SFML.Audio/SoundRecorder.cs b/src/SFML.Audio/SoundRecorder.cs index 3017ac7f..0e068539 100644 --- a/src/SFML.Audio/SoundRecorder.cs +++ b/src/SFML.Audio/SoundRecorder.cs @@ -204,10 +204,10 @@ public static string[] AvailableDevices { unsafe { - uint Count; + UIntPtr Count; IntPtr* DevicesPtr = sfSoundRecorder_getAvailableDevices(out Count); - string[] Devices = new string[Count]; - for (uint i = 0; i < Count; ++i) + string[] Devices = new string[(int)Count]; + for (int i = 0; i < (int)Count; ++i) { Devices[i] = Marshal.PtrToStringAnsi(DevicesPtr[i]); } @@ -284,9 +284,9 @@ private bool StartRecording(IntPtr userData) /// User data -- unused /// False to stop recording audio data, true to continue //////////////////////////////////////////////////////////// - private bool ProcessSamples(IntPtr samples, uint nbSamples, IntPtr userData) + private bool ProcessSamples(IntPtr samples, UIntPtr nbSamples, IntPtr userData) { - short[] samplesArray = new short[nbSamples]; + short[] samplesArray = new short[(int)nbSamples]; Marshal.Copy(samples, samplesArray, 0, samplesArray.Length); return OnProcessSamples(samplesArray); @@ -308,7 +308,7 @@ private void StopRecording(IntPtr userData) private delegate bool StartCallback(IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool ProcessCallback(IntPtr samples, uint nbSamples, IntPtr userData); + private delegate bool ProcessCallback(IntPtr samples, UIntPtr nbSamples, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void StopCallback(IntPtr userData); @@ -340,7 +340,7 @@ private void StopRecording(IntPtr userData) private static extern void sfSoundRecorder_setProcessingInterval(IntPtr SoundRecorder, Time Interval); [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr* sfSoundRecorder_getAvailableDevices(out uint Count); + private unsafe static extern IntPtr* sfSoundRecorder_getAvailableDevices(out UIntPtr Count); [DllImport(CSFML.audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfSoundRecorder_getDefaultDevice(); diff --git a/src/SFML.Graphics/Font.cs b/src/SFML.Graphics/Font.cs index d07cdb28..308a0bac 100644 --- a/src/SFML.Graphics/Font.cs +++ b/src/SFML.Graphics/Font.cs @@ -41,8 +41,10 @@ public Font(string filename) : base(sfFont_createFromFile(filename)) //////////////////////////////////////////////////////////// public Font(Stream stream) : base(IntPtr.Zero) { - myStream = new StreamAdaptor(stream); - CPointer = sfFont_createFromStream(myStream.InputStreamPtr); + using (var adaptor = new StreamAdaptor(stream)) + { + CPointer = sfFont_createFromStream(adaptor.InputStreamPtr); + } if (CPointer == IntPtr.Zero) { @@ -57,7 +59,23 @@ public Font(Stream stream) : base(IntPtr.Zero) /// Byte array containing the file contents /// //////////////////////////////////////////////////////////// - public Font(byte[] bytes) : this(new MemoryStream(bytes)) { } + public Font(byte[] bytes) : + base(IntPtr.Zero) + { + GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); + try + { + CPointer = sfFont_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); + } + finally + { + pin.Free(); + } + if (CPointer == IntPtr.Zero) + { + throw new LoadingFailedException("font"); + } + } //////////////////////////////////////////////////////////// /// @@ -265,7 +283,7 @@ internal struct InfoMarshalData private static extern IntPtr sfFont_createFromStream(IntPtr stream); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfFont_createFromMemory(IntPtr data, ulong size); + private static extern IntPtr sfFont_createFromMemory(IntPtr data, UIntPtr size); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfFont_copy(IntPtr Font); diff --git a/src/SFML.Graphics/Image.cs b/src/SFML.Graphics/Image.cs index 3d8c672e..cecaf5a9 100644 --- a/src/SFML.Graphics/Image.cs +++ b/src/SFML.Graphics/Image.cs @@ -90,7 +90,7 @@ public Image(byte[] bytes) : GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { - CPointer = sfImage_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length)); + CPointer = sfImage_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length); } finally { @@ -389,7 +389,7 @@ protected override void Destroy(bool disposing) private unsafe static extern IntPtr sfImage_createFromStream(IntPtr stream); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr sfImage_createFromMemory(IntPtr data, ulong size); + private unsafe static extern IntPtr sfImage_createFromMemory(IntPtr data, UIntPtr size); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfImage_copy(IntPtr Image); diff --git a/src/SFML.Graphics/RenderTexture.cs b/src/SFML.Graphics/RenderTexture.cs index 3a46dbaf..8aaed8bc 100644 --- a/src/SFML.Graphics/RenderTexture.cs +++ b/src/SFML.Graphics/RenderTexture.cs @@ -410,7 +410,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type, { fixed (Vertex* vertexPtr = vertices) { - sfRenderTexture_drawPrimitives(CPointer, vertexPtr + start, count, type, ref marshaledStates); + sfRenderTexture_drawPrimitives(CPointer, vertexPtr + start, (UIntPtr)count, type, ref marshaledStates); } } } @@ -599,7 +599,7 @@ protected override void Destroy(bool disposing) private static extern bool sfRenderTexture_generateMipmap(IntPtr CPointer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfRenderTexture_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, uint vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); + private unsafe static extern void sfRenderTexture_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, UIntPtr vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfRenderTexture_pushGLStates(IntPtr CPointer); diff --git a/src/SFML.Graphics/RenderWindow.cs b/src/SFML.Graphics/RenderWindow.cs index 749dbde7..4bb0a2e3 100644 --- a/src/SFML.Graphics/RenderWindow.cs +++ b/src/SFML.Graphics/RenderWindow.cs @@ -602,7 +602,7 @@ public void Draw(Vertex[] vertices, uint start, uint count, PrimitiveType type, { fixed (Vertex* vertexPtr = vertices) { - sfRenderWindow_drawPrimitives(CPointer, vertexPtr + start, count, type, ref marshaledStates); + sfRenderWindow_drawPrimitives(CPointer, vertexPtr + start, (UIntPtr)count, type, ref marshaledStates); } } } @@ -930,7 +930,7 @@ private void Initialize() private static extern Vector2i sfRenderWindow_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern void sfRenderWindow_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, uint vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); + private unsafe static extern void sfRenderWindow_drawPrimitives(IntPtr CPointer, Vertex* vertexPtr, UIntPtr vertexCount, PrimitiveType type, ref RenderStates.MarshalData renderStates); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfRenderWindow_pushGLStates(IntPtr CPointer); diff --git a/src/SFML.Graphics/Shader.cs b/src/SFML.Graphics/Shader.cs index f49f6824..8850ea35 100644 --- a/src/SFML.Graphics/Shader.cs +++ b/src/SFML.Graphics/Shader.cs @@ -406,7 +406,7 @@ public unsafe void SetUniformArray(string name, float[] array) { fixed (float* data = array) { - sfShader_setFloatUniformArray(CPointer, name, data, (uint)array.Length); + sfShader_setFloatUniformArray(CPointer, name, data, (UIntPtr)array.Length); } } @@ -421,7 +421,7 @@ public unsafe void SetUniformArray(string name, Glsl.Vec2[] array) { fixed (Glsl.Vec2* data = array) { - sfShader_setVec2UniformArray(CPointer, name, data, (uint)array.Length); + sfShader_setVec2UniformArray(CPointer, name, data, (UIntPtr)array.Length); } } @@ -436,7 +436,7 @@ public unsafe void SetUniformArray(string name, Glsl.Vec3[] array) { fixed (Glsl.Vec3* data = array) { - sfShader_setVec3UniformArray(CPointer, name, data, (uint)array.Length); + sfShader_setVec3UniformArray(CPointer, name, data, (UIntPtr)array.Length); } } @@ -451,7 +451,7 @@ public unsafe void SetUniformArray(string name, Glsl.Vec4[] array) { fixed (Glsl.Vec4* data = array) { - sfShader_setVec4UniformArray(CPointer, name, data, (uint)array.Length); + sfShader_setVec4UniformArray(CPointer, name, data, (UIntPtr)array.Length); } } @@ -466,7 +466,7 @@ public unsafe void SetUniformArray(string name, Glsl.Mat3[] array) { fixed (Glsl.Mat3* data = array) { - sfShader_setMat3UniformArray(CPointer, name, data, (uint)array.Length); + sfShader_setMat3UniformArray(CPointer, name, data, (UIntPtr)array.Length); } } @@ -481,7 +481,7 @@ public unsafe void SetUniformArray(string name, Glsl.Mat4[] array) { fixed (Glsl.Mat4* data = array) { - sfShader_setMat4UniformArray(CPointer, name, data, (uint)array.Length); + sfShader_setMat4UniformArray(CPointer, name, data, (UIntPtr)array.Length); } } @@ -816,22 +816,22 @@ public Shader(IntPtr ptr) : private static extern void sfShader_setCurrentTextureUniform(IntPtr shader, string name); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe void sfShader_setFloatUniformArray(IntPtr shader, string name, float* data, uint length); + private static extern unsafe void sfShader_setFloatUniformArray(IntPtr shader, string name, float* data, UIntPtr length); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe void sfShader_setVec2UniformArray(IntPtr shader, string name, Glsl.Vec2* data, uint length); + private static extern unsafe void sfShader_setVec2UniformArray(IntPtr shader, string name, Glsl.Vec2* data, UIntPtr length); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe void sfShader_setVec3UniformArray(IntPtr shader, string name, Glsl.Vec3* data, uint length); + private static extern unsafe void sfShader_setVec3UniformArray(IntPtr shader, string name, Glsl.Vec3* data, UIntPtr length); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe void sfShader_setVec4UniformArray(IntPtr shader, string name, Glsl.Vec4* data, uint length); + private static extern unsafe void sfShader_setVec4UniformArray(IntPtr shader, string name, Glsl.Vec4* data, UIntPtr length); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe void sfShader_setMat3UniformArray(IntPtr shader, string name, Glsl.Mat3* data, uint length); + private static extern unsafe void sfShader_setMat3UniformArray(IntPtr shader, string name, Glsl.Mat3* data, UIntPtr length); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe void sfShader_setMat4UniformArray(IntPtr shader, string name, Glsl.Mat4* data, uint length); + private static extern unsafe void sfShader_setMat4UniformArray(IntPtr shader, string name, Glsl.Mat4* data, UIntPtr length); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity, Obsolete] private static extern void sfShader_setFloatParameter(IntPtr shader, string name, float x); diff --git a/src/SFML.Graphics/Shape.cs b/src/SFML.Graphics/Shape.cs index 8623cb4f..beba90d3 100644 --- a/src/SFML.Graphics/Shape.cs +++ b/src/SFML.Graphics/Shape.cs @@ -215,9 +215,9 @@ protected override void Destroy(bool disposing) /// Callback passed to the C API /// //////////////////////////////////////////////////////////// - private uint InternalGetPointCount(IntPtr userData) + private UIntPtr InternalGetPointCount(IntPtr userData) { - return GetPointCount(); + return (UIntPtr)GetPointCount(); } //////////////////////////////////////////////////////////// @@ -225,16 +225,16 @@ private uint InternalGetPointCount(IntPtr userData) /// Callback passed to the C API /// //////////////////////////////////////////////////////////// - private Vector2f InternalGetPoint(uint index, IntPtr userData) + private Vector2f InternalGetPoint(UIntPtr index, IntPtr userData) { - return GetPoint(index); + return GetPoint((uint)index); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate uint GetPointCountCallbackType(IntPtr UserData); + private delegate UIntPtr GetPointCountCallbackType(IntPtr UserData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate Vector2f GetPointCallbackType(uint index, IntPtr UserData); + private delegate Vector2f GetPointCallbackType(UIntPtr index, IntPtr UserData); private readonly GetPointCountCallbackType myGetPointCountCallback; private readonly GetPointCallbackType myGetPointCallback; diff --git a/src/SFML.Graphics/Text.cs b/src/SFML.Graphics/Text.cs index c2094924..7df99617 100644 --- a/src/SFML.Graphics/Text.cs +++ b/src/SFML.Graphics/Text.cs @@ -282,7 +282,7 @@ public Styles Style //////////////////////////////////////////////////////////// public Vector2f FindCharacterPos(uint index) { - return sfText_findCharacterPos(CPointer, index); + return sfText_findCharacterPos(CPointer, (UIntPtr)index); } //////////////////////////////////////////////////////////// @@ -451,7 +451,7 @@ protected override void Destroy(bool disposing) private static extern Styles sfText_getStyle(IntPtr CPointer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern Vector2f sfText_findCharacterPos(IntPtr CPointer, uint Index); + private static extern Vector2f sfText_findCharacterPos(IntPtr CPointer, UIntPtr Index); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern FloatRect sfText_getLocalBounds(IntPtr CPointer); diff --git a/src/SFML.Graphics/Texture.cs b/src/SFML.Graphics/Texture.cs index e15ef888..67f563a7 100644 --- a/src/SFML.Graphics/Texture.cs +++ b/src/SFML.Graphics/Texture.cs @@ -211,12 +211,12 @@ public Texture(byte[] bytes, IntRect area, bool srgb = false) : { if (srgb) { - CPointer = sfTexture_createSrgbFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref area); + CPointer = sfTexture_createSrgbFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length, ref area); } else { - CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref area); - } + CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), (UIntPtr)bytes.Length, ref area); + } } finally { @@ -582,10 +582,10 @@ protected override void Destroy(bool disposing) private static extern IntPtr sfTexture_createSrgbFromImage(IntPtr image, ref IntRect area); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfTexture_createFromMemory(IntPtr data, ulong size, ref IntRect area); + private static extern IntPtr sfTexture_createFromMemory(IntPtr data, UIntPtr size, ref IntRect area); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr sfTexture_createSrgbFromMemory(IntPtr data, ulong size, ref IntRect area); + private static extern IntPtr sfTexture_createSrgbFromMemory(IntPtr data, UIntPtr size, ref IntRect area); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfTexture_copy(IntPtr texture); diff --git a/src/SFML.Graphics/VertexArray.cs b/src/SFML.Graphics/VertexArray.cs index 58922154..2c2f516a 100644 --- a/src/SFML.Graphics/VertexArray.cs +++ b/src/SFML.Graphics/VertexArray.cs @@ -66,7 +66,7 @@ public VertexArray(VertexArray copy) : //////////////////////////////////////////////////////////// public uint VertexCount { - get { return sfVertexArray_getVertexCount(CPointer); } + get { return (uint)sfVertexArray_getVertexCount(CPointer); } } //////////////////////////////////////////////////////////// @@ -87,14 +87,14 @@ public Vertex this[uint index] { unsafe { - return *sfVertexArray_getVertex(CPointer, index); + return *sfVertexArray_getVertex(CPointer, (UIntPtr)index); } } set { unsafe { - *sfVertexArray_getVertex(CPointer, index) = value; + *sfVertexArray_getVertex(CPointer, (UIntPtr)index) = value; } } } @@ -124,7 +124,7 @@ public void Clear() //////////////////////////////////////////////////////////// public void Resize(uint vertexCount) { - sfVertexArray_resize(CPointer, vertexCount); + sfVertexArray_resize(CPointer, (UIntPtr)vertexCount); } //////////////////////////////////////////////////////////// @@ -208,16 +208,16 @@ protected override void Destroy(bool disposing) private static extern void sfVertexArray_destroy(IntPtr CPointer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfVertexArray_getVertexCount(IntPtr CPointer); + private static extern UIntPtr sfVertexArray_getVertexCount(IntPtr CPointer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern unsafe Vertex* sfVertexArray_getVertex(IntPtr CPointer, uint index); + private static extern unsafe Vertex* sfVertexArray_getVertex(IntPtr CPointer, UIntPtr index); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfVertexArray_clear(IntPtr CPointer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfVertexArray_resize(IntPtr CPointer, uint vertexCount); + private static extern void sfVertexArray_resize(IntPtr CPointer, UIntPtr vertexCount); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfVertexArray_append(IntPtr CPointer, Vertex vertex); diff --git a/src/SFML.Graphics/VertexBuffer.cs b/src/SFML.Graphics/VertexBuffer.cs index f7d9a0b4..ab1e0276 100644 --- a/src/SFML.Graphics/VertexBuffer.cs +++ b/src/SFML.Graphics/VertexBuffer.cs @@ -330,11 +330,11 @@ public void Draw(RenderTarget target, uint firstVertex, uint vertexCount, Render if (target is RenderWindow) { - sfRenderWindow_drawVertexBufferRange(( (RenderWindow)target ).CPointer, CPointer, firstVertex, vertexCount, ref marshaledStates); + sfRenderWindow_drawVertexBufferRange(( (RenderWindow)target ).CPointer, CPointer, (UIntPtr)firstVertex, (UIntPtr)vertexCount, ref marshaledStates); } else if (target is RenderTexture) { - sfRenderTexture_drawVertexBufferRange(( (RenderTexture)target ).CPointer, CPointer, firstVertex, vertexCount, ref marshaledStates); + sfRenderTexture_drawVertexBufferRange(( (RenderTexture)target ).CPointer, CPointer, (UIntPtr)firstVertex, (UIntPtr)vertexCount, ref marshaledStates); } } @@ -385,13 +385,13 @@ public void Draw(RenderTarget target, uint firstVertex, uint vertexCount, Render private static extern void sfRenderWindow_drawVertexBuffer(IntPtr CPointer, IntPtr VertexArray, ref RenderStates.MarshalData states); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderWindow_drawVertexBufferRange(IntPtr CPointer, IntPtr VertexBuffer, uint firstVertex, uint vertexCount, ref RenderStates.MarshalData states); + private static extern void sfRenderWindow_drawVertexBufferRange(IntPtr CPointer, IntPtr VertexBuffer, UIntPtr firstVertex, UIntPtr vertexCount, ref RenderStates.MarshalData states); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern void sfRenderTexture_drawVertexBuffer(IntPtr CPointer, IntPtr VertexBuffer, ref RenderStates.MarshalData states); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern void sfRenderTexture_drawVertexBufferRange(IntPtr CPointer, IntPtr VertexBuffer, uint firstVertex, uint vertexCount, ref RenderStates.MarshalData states); + private static extern void sfRenderTexture_drawVertexBufferRange(IntPtr CPointer, IntPtr VertexBuffer, UIntPtr firstVertex, UIntPtr vertexCount, ref RenderStates.MarshalData states); #endregion } } diff --git a/src/SFML.System/Buffer.cs b/src/SFML.System/Buffer.cs index 2a4b309c..abfb2d68 100644 --- a/src/SFML.System/Buffer.cs +++ b/src/SFML.System/Buffer.cs @@ -42,7 +42,7 @@ public byte[] GetData() return Array.Empty(); } - var data = new byte[size]; + var data = new byte[(int)size]; Marshal.Copy(ptr, data, 0, (int)size); return data; @@ -78,7 +78,7 @@ protected override void Destroy(bool disposing) private static extern void sfBuffer_destroy(IntPtr buffer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern uint sfBuffer_getSize(IntPtr buffer); + private static extern UIntPtr sfBuffer_getSize(IntPtr buffer); [DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern IntPtr sfBuffer_getData(IntPtr buffer); diff --git a/src/SFML.Window/VideoMode.cs b/src/SFML.Window/VideoMode.cs index 8e8df321..1bd93afb 100644 --- a/src/SFML.Window/VideoMode.cs +++ b/src/SFML.Window/VideoMode.cs @@ -1,3 +1,4 @@ +using System; using System.Runtime.InteropServices; using System.Security; using SFML.System; @@ -63,10 +64,10 @@ public static VideoMode[] FullscreenModes { unsafe { - uint Count; + UIntPtr Count; VideoMode* ModesPtr = sfVideoMode_getFullscreenModes(out Count); - VideoMode[] Modes = new VideoMode[Count]; - for (uint i = 0; i < Count; ++i) + VideoMode[] Modes = new VideoMode[(int)Count]; + for (int i = 0; i < (int)Count; ++i) { Modes[i] = ModesPtr[i]; } @@ -114,7 +115,7 @@ public override string ToString() private static extern VideoMode sfVideoMode_getDesktopMode(); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern VideoMode* sfVideoMode_getFullscreenModes(out uint Count); + private unsafe static extern VideoMode* sfVideoMode_getFullscreenModes(out UIntPtr Count); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern bool sfVideoMode_isValid(VideoMode Mode); diff --git a/src/SFML.Window/Vulkan.cs b/src/SFML.Window/Vulkan.cs index 1d8a376a..69dee7ab 100644 --- a/src/SFML.Window/Vulkan.cs +++ b/src/SFML.Window/Vulkan.cs @@ -45,9 +45,9 @@ public static string[] GetGraphicsRequiredInstanceExtensions() unsafe { var extensionsPtr = sfVulkan_getGraphicsRequiredInstanceExtensions(out var count); - var extensions = new string[count]; + var extensions = new string[(int)count]; - for (uint i = 0; i < count; ++i) + for (int i = 0; i < (int)count; ++i) { extensions[i] = Marshal.PtrToStringAnsi(extensionsPtr[i]); } @@ -64,7 +64,7 @@ public static string[] GetGraphicsRequiredInstanceExtensions() private static extern IntPtr sfVulkan_getFunction(string name); [DllImport(CSFML.window, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private unsafe static extern IntPtr* sfVulkan_getGraphicsRequiredInstanceExtensions(out uint count); + private unsafe static extern IntPtr* sfVulkan_getGraphicsRequiredInstanceExtensions(out UIntPtr count); #endregion } } \ No newline at end of file