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

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using RefreshCS;
namespace MoonWorks.Graphics
@ -1406,7 +1407,7 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
(IntPtr) uniformsPtr,
(uint) sizeof(T)
(uint) Marshal.SizeOf<T>()
);
}
}
@ -1433,7 +1434,7 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
(IntPtr) uniformsPtr,
(uint) sizeof(T)
(uint) Marshal.SizeOf<T>()
);
}
}
@ -1461,7 +1462,7 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
(IntPtr) uniformsPtr,
(uint) sizeof(T)
(uint) Marshal.SizeOf<T>()
);
}
}
@ -1720,7 +1721,7 @@ namespace MoonWorks.Graphics
AssertRenderPassInactive("Cannot copy during render pass!");
#endif
var elementSize = sizeof(T);
var elementSize = Marshal.SizeOf<T>();
fixed (T* ptr = &data[startElement])
{
@ -1749,9 +1750,9 @@ namespace MoonWorks.Graphics
Device.Handle,
Handle,
buffer.Handle,
(uint) sizeof(T) * bufferOffsetInElements,
(uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
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])
{
var nativeSize = fontRanges.Length * sizeof(Wellspring.FontRange);
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange));
var nativeSize = fontRanges.Length * Marshal.SizeOf<Wellspring.FontRange>();
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.SizeOf<Wellspring.FontRange>());
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);

View File

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

View File

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

View File

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

View File

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