Skip to content

Commit

Permalink
Remove MarshalHelper
Browse files Browse the repository at this point in the history
Not necessary anymore since .NET Core
  • Loading branch information
PJB3005 committed Jun 12, 2022
1 parent 7655aec commit 1e7956e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 113 deletions.
35 changes: 17 additions & 18 deletions OpenToolkit.GraphicsLibraryFramework/GLFW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System;
using System.Runtime.InteropServices;
using static OpenToolkit.GraphicsLibraryFramework.GLFWNative;
using static Robust.Shared.Utility.MarshalHelper;

namespace OpenToolkit.GraphicsLibraryFramework
{
Expand Down Expand Up @@ -211,7 +210,7 @@ public static unsafe void GetVersion(out int major, out int minor, out int revis
/// <seealso cref="GetVersion"/>
public static unsafe string GetVersionString()
{
return PtrToStringUTF8(glfwGetVersionString());
return Marshal.PtrToStringUTF8((IntPtr) glfwGetVersionString());
}

/// <summary>
Expand Down Expand Up @@ -272,7 +271,7 @@ public static unsafe ErrorCode GetError(out string description)
{
byte* desc;
var code = glfwGetError(&desc);
description = PtrToStringUTF8(desc);
description = Marshal.PtrToStringUTF8((IntPtr) desc);
return code;
}

Expand Down Expand Up @@ -590,7 +589,7 @@ public static unsafe void GetMonitorContentScaleRaw(Monitor* monitor, float* xSc
/// </remarks>
public static unsafe string GetMonitorName(Monitor* monitor)
{
return PtrToStringUTF8(glfwGetMonitorName(monitor));
return Marshal.PtrToStringUTF8((IntPtr) glfwGetMonitorName(monitor));
}

/// <summary>
Expand Down Expand Up @@ -902,7 +901,7 @@ public static unsafe void SetGammaRamp(Monitor* monitor, GammaRamp* ramp)
/// </remarks>
public static unsafe void WindowHint(WindowHintString hint, string value)
{
var ptr = StringToCoTaskMemUTF8(value);
var ptr = Marshal.StringToCoTaskMemUTF8(value);

try
{
Expand Down Expand Up @@ -1364,7 +1363,7 @@ public static bool RawMouseMotionSupported()
/// </remarks>
public static unsafe string GetKeyName(Keys key, int scanCode)
{
return PtrToStringUTF8(glfwGetKeyName(key, scanCode));
return Marshal.PtrToStringUTF8((IntPtr) glfwGetKeyName(key, scanCode));
}

/// <summary>
Expand Down Expand Up @@ -2278,7 +2277,7 @@ public static unsafe JoystickHats[] GetJoystickHats(int jid)
/// </remarks>
public static unsafe string GetJoystickName(int jid)
{
return PtrToStringUTF8(glfwGetJoystickName(jid));
return Marshal.PtrToStringUTF8((IntPtr) glfwGetJoystickName(jid));
}

/// <summary>
Expand Down Expand Up @@ -2351,7 +2350,7 @@ public static unsafe string GetJoystickName(int jid)
/// </remarks>
public static unsafe string GetJoystickGUID(int jid)
{
return PtrToStringUTF8(glfwGetJoystickGUID(jid));
return Marshal.PtrToStringUTF8((IntPtr) glfwGetJoystickGUID(jid));
}

/// <summary>
Expand Down Expand Up @@ -2509,7 +2508,7 @@ public static bool JoystickIsGamepad(int jid)
/// </remarks>
public static unsafe bool UpdateGamepadMappings(string newMapping)
{
var ptr = StringToCoTaskMemUTF8(newMapping);
var ptr = Marshal.StringToCoTaskMemUTF8(newMapping);
try
{
return glfwUpdateGamepadMappings((byte*)ptr) == GLFW_TRUE;
Expand Down Expand Up @@ -2585,7 +2584,7 @@ public static unsafe bool UpdateGamepadMappingsRaw(byte* newMapping)
/// </remarks>
public static unsafe string GetGamepadName(int jid)
{
return PtrToStringUTF8(glfwGetGamepadName(jid));
return Marshal.PtrToStringUTF8((IntPtr) glfwGetGamepadName(jid));
}

/// <summary>
Expand Down Expand Up @@ -2854,7 +2853,7 @@ public static unsafe bool GetGamepadStateRaw(int jid, GamepadState* state)
/// </remarks>
public static unsafe bool ExtensionSupported(string extensionName)
{
var ptr = StringToCoTaskMemUTF8(extensionName);
var ptr = Marshal.StringToCoTaskMemUTF8(extensionName);

try
{
Expand Down Expand Up @@ -2893,7 +2892,7 @@ public static unsafe bool ExtensionSupported(string extensionName)
/// <seealso cref="ExtensionSupported" />
public static unsafe IntPtr GetProcAddress(string procName)
{
var ptr = StringToCoTaskMemUTF8(procName);
var ptr = Marshal.StringToCoTaskMemUTF8(procName);

try
{
Expand Down Expand Up @@ -3085,7 +3084,7 @@ public static unsafe bool ExtensionSupportedRaw(byte* extensionName)
/// </remarks>
public static unsafe Window* CreateWindow(int width, int height, string title, Monitor* monitor, Window* share)
{
var ptr = StringToCoTaskMemUTF8(title);
var ptr = Marshal.StringToCoTaskMemUTF8(title);

try
{
Expand Down Expand Up @@ -3306,7 +3305,7 @@ public static unsafe bool ExtensionSupportedRaw(byte* extensionName)
/// <seealso cref="SetClipboardString"/>
public static unsafe string GetClipboardString(Window* window)
{
return PtrToStringUTF8(glfwGetClipboardString(window));
return Marshal.PtrToStringUTF8((IntPtr) glfwGetClipboardString(window));
}

/// <summary>
Expand Down Expand Up @@ -3917,7 +3916,7 @@ public static unsafe IntPtr SetCharModsCallback(
/// <seealso cref="GetClipboardString"/>
public static unsafe void SetClipboardString(Window* window, string data)
{
var ptr = StringToCoTaskMemUTF8(data);
var ptr = Marshal.StringToCoTaskMemUTF8(data);

try
{
Expand Down Expand Up @@ -4751,7 +4750,7 @@ public static unsafe void SetWindowShouldClose(Window* window, bool value)
/// </remarks>
public static unsafe void SetWindowTitle(Window* window, string title)
{
var ptr = StringToCoTaskMemUTF8(title);
var ptr = Marshal.StringToCoTaskMemUTF8(title);

try
{
Expand Down Expand Up @@ -5340,7 +5339,7 @@ public static unsafe string[] GetRequiredInstanceExtensions()
var array = new string[count];
for (var i = 0; i < count; i++)
{
array[i] = PtrToStringUTF8(ptr[i]);
array[i] = Marshal.PtrToStringUTF8((IntPtr) ptr[i]);
}

return array;
Expand Down Expand Up @@ -5386,7 +5385,7 @@ public static unsafe string[] GetRequiredInstanceExtensions()
/// <returns>The address of the function, or <c>null</c> if an error occurred.</returns>
public static unsafe IntPtr GetInstanceProcAddress(VkHandle instance, string procName)
{
var ptr = StringToCoTaskMemUTF8(procName);
var ptr = Marshal.StringToCoTaskMemUTF8(procName);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
<PackageReference Condition="'$(TargetFramework)' == 'net472'" Include="System.Memory" Version="4.5.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Robust.Shared\Robust.Shared.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Robust.Client/UserInterface/FileDialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ private static IntPtr FormatFiltersNfd(FileDialogFilters? filters)
{
case sw_nfdresult.SW_NFD_ERROR:
var errPtr = sw_NFD_GetError();
throw new Exception(MarshalHelper.PtrToStringUTF8(errPtr));
throw new Exception(Marshal.PtrToStringUTF8((IntPtr) errPtr));

case sw_nfdresult.SW_NFD_OKAY:
var str = MarshalHelper.PtrToStringUTF8(outPath)!;
var str = Marshal.PtrToStringUTF8((IntPtr) outPath)!;

sw_NFD_Free(outPath);
return str;
Expand Down
68 changes: 0 additions & 68 deletions Robust.Shared/Utility/MarshalHelper.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Robust.UnitTesting/Shared/Utility/MarshalHelper_Test.cs

This file was deleted.

0 comments on commit 1e7956e

Please sign in to comment.