change sizeof calls to Marshal.SizeOf in interop situations

pull/37/head
cosmonaut 2022-12-13 19:01:40 -08:00
parent debb76f62a
commit d76633bdfc
7 changed files with 19 additions and 17 deletions

View File

@ -118,13 +118,13 @@ namespace MoonWorks.Audio
IntPtr chainPtr; IntPtr chainPtr;
chainPtr = Marshal.AllocHGlobal( chainPtr = Marshal.AllocHGlobal(
sizeof(FAudio.FAudioEffectChain) Marshal.SizeOf<FAudio.FAudioEffectChain>()
); );
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr; FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
reverbChain->EffectCount = 1; reverbChain->EffectCount = 1;
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal( reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
sizeof(FAudio.FAudioEffectDescriptor) Marshal.SizeOf<FAudio.FAudioEffectDescriptor>()
); );
FAudio.FAudioEffectDescriptor* reverbDescriptor = FAudio.FAudioEffectDescriptor* reverbDescriptor =
@ -157,7 +157,7 @@ namespace MoonWorks.Audio
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC // Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
IntPtr reverbParamsPtr = Marshal.AllocHGlobal( IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
sizeof(FAudio.FAudioFXReverbParameters) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>()
); );
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr; FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
@ -187,7 +187,7 @@ namespace MoonWorks.Audio
ReverbVoice, ReverbVoice,
0, 0,
reverbParamsPtr, reverbParamsPtr,
(uint) sizeof(FAudio.FAudioFXReverbParameters), (uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
0 0
); );
Marshal.FreeHGlobal(reverbParamsPtr); Marshal.FreeHGlobal(reverbParamsPtr);
@ -198,7 +198,7 @@ namespace MoonWorks.Audio
{ {
SendCount = 2, SendCount = 2,
pSends = Marshal.AllocHGlobal( pSends = Marshal.AllocHGlobal(
2 * sizeof(FAudio.FAudioSendDescriptor) 2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
) )
}; };
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends; FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.InteropServices;
using RefreshCS; using RefreshCS;
namespace MoonWorks.Graphics namespace MoonWorks.Graphics
@ -1406,7 +1407,7 @@ namespace MoonWorks.Graphics
Device.Handle, Device.Handle,
Handle, Handle,
(IntPtr) uniformsPtr, (IntPtr) uniformsPtr,
(uint) sizeof(T) (uint) Marshal.SizeOf<T>()
); );
} }
} }
@ -1433,7 +1434,7 @@ namespace MoonWorks.Graphics
Device.Handle, Device.Handle,
Handle, Handle,
(IntPtr) uniformsPtr, (IntPtr) uniformsPtr,
(uint) sizeof(T) (uint) Marshal.SizeOf<T>()
); );
} }
} }
@ -1461,7 +1462,7 @@ namespace MoonWorks.Graphics
Device.Handle, Device.Handle,
Handle, Handle,
(IntPtr) uniformsPtr, (IntPtr) uniformsPtr,
(uint) sizeof(T) (uint) Marshal.SizeOf<T>()
); );
} }
} }
@ -1720,7 +1721,7 @@ namespace MoonWorks.Graphics
AssertRenderPassInactive("Cannot copy during render pass!"); AssertRenderPassInactive("Cannot copy during render pass!");
#endif #endif
var elementSize = sizeof(T); var elementSize = Marshal.SizeOf<T>();
fixed (T* ptr = &data[startElement]) fixed (T* ptr = &data[startElement])
{ {
@ -1749,9 +1750,9 @@ namespace MoonWorks.Graphics
Device.Handle, Device.Handle,
Handle, Handle,
buffer.Handle, buffer.Handle,
(uint) sizeof(T) * bufferOffsetInElements, (uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
dataPtr, dataPtr,
(uint) sizeof(T) * numElements (uint) Marshal.SizeOf<T>() * numElements
); );
} }

View File

@ -28,8 +28,8 @@ namespace MoonWorks.Graphics.Font
{ {
fixed (FontRange *pFontRanges = &fontRanges[0]) fixed (FontRange *pFontRanges = &fontRanges[0])
{ {
var nativeSize = fontRanges.Length * sizeof(Wellspring.FontRange); var nativeSize = fontRanges.Length * Marshal.SizeOf<Wellspring.FontRange>();
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange)); void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.SizeOf<Wellspring.FontRange>());
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize); System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length); var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);

View File

@ -134,7 +134,7 @@ namespace MoonWorks.Graphics
{ {
Binding = 0, Binding = 0,
InputRate = VertexInputRate.Vertex, InputRate = VertexInputRate.Vertex,
Stride = (uint) sizeof(T) Stride = (uint) Marshal.SizeOf<T>()
}; };
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.InteropServices;
using RefreshCS; using RefreshCS;
namespace MoonWorks.Graphics namespace MoonWorks.Graphics
@ -32,7 +33,7 @@ namespace MoonWorks.Graphics
return new Buffer( return new Buffer(
device, device,
usageFlags, usageFlags,
(uint) sizeof(T) * elementCount (uint) Marshal.SizeOf<T>() * elementCount
); );
} }

View File

@ -24,7 +24,7 @@ namespace MoonWorks.Graphics
{ {
ShaderModule = shaderModule, ShaderModule = shaderModule,
EntryPointName = entryPointName, EntryPointName = entryPointName,
UniformBufferSize = (uint) sizeof(T), UniformBufferSize = (uint) Marshal.SizeOf<T>(),
BufferBindingCount = bufferBindingCount, BufferBindingCount = bufferBindingCount,
ImageBindingCount = imageBindingCount ImageBindingCount = imageBindingCount
}; };

View File

@ -22,7 +22,7 @@ namespace MoonWorks.Graphics
{ {
ShaderModule = shaderModule, ShaderModule = shaderModule,
EntryPointName = entryPointName, EntryPointName = entryPointName,
UniformBufferSize = (uint) sizeof(T), UniformBufferSize = (uint) Marshal.SizeOf<T>(),
SamplerBindingCount = samplerBindingCount SamplerBindingCount = samplerBindingCount
}; };
} }