SDL3MotionDriver: This calls "SDL_OpenSensor" in constructor, made disposable to call "SDL_CloseSensor" on dispose

This commit is contained in:
Barış Hamil 2024-08-30 21:45:52 +03:00
parent f9caeb6b44
commit 93bfb604c5

View file

@ -7,7 +7,8 @@ using System.Numerics;
using static SDL3.SDL3;
namespace Ryujinx.SDL3;
public unsafe class SDL3MotionDriver : IHandheld
public unsafe class SDL3MotionDriver : IHandheld, IDisposable
{
private Dictionary<SDL_SensorType, SDL_Sensor> sensors;
public SDL3MotionDriver()
@ -16,6 +17,14 @@ public unsafe class SDL3MotionDriver : IHandheld
sensors = SDL_GetSensors().ToArray().ToDictionary(SDL_GetSensorTypeForID, SDL_OpenSensor);
}
public void Dispose()
{
foreach (var sensor in sensors.Values)
{
SDL_CloseSensor(sensor);
}
}
public Vector3 GetMotionData(MotionInputId gyroscope)
{
var data = stackalloc float[3];