mirror of https://github.com/ppy/SDL3-CS.git
Merge pull request #185 from Susko3/fix-SDL_GetWindows-managed-helper
Fix `SDL_GetWindows()` managed helper
This commit is contained in:
commit
09cd92181a
|
|
@ -32,6 +32,8 @@ namespace SDL.Tests
|
||||||
window.Setup();
|
window.Setup();
|
||||||
window.Create();
|
window.Create();
|
||||||
|
|
||||||
|
printWindows();
|
||||||
|
|
||||||
const SDL_Keymod state = SDL_Keymod.SDL_KMOD_CAPS | SDL_Keymod.SDL_KMOD_ALT;
|
const SDL_Keymod state = SDL_Keymod.SDL_KMOD_CAPS | SDL_Keymod.SDL_KMOD_ALT;
|
||||||
SDL_SetModState(state);
|
SDL_SetModState(state);
|
||||||
Debug.Assert(SDL_GetModState() == state);
|
Debug.Assert(SDL_GetModState() == state);
|
||||||
|
|
@ -64,5 +66,17 @@ namespace SDL.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static unsafe void printWindows()
|
||||||
|
{
|
||||||
|
using var windows = SDL_GetWindows();
|
||||||
|
if (windows == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < windows.Count; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Window {i} title: {SDL_GetWindowTitle(windows[i])}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,11 @@ namespace SDL
|
||||||
}
|
}
|
||||||
|
|
||||||
[MustDisposeResource]
|
[MustDisposeResource]
|
||||||
public static unsafe SDLPointerArray<SDL_Window>? SDL_GetWindows()
|
public static unsafe SDLOpaquePointerArray<SDL_Window>? SDL_GetWindows()
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
var array = SDL_GetWindows(&count);
|
var array = SDL_GetWindows(&count);
|
||||||
return SDLArray.Create(array, count);
|
return SDLArray.CreateOpaque(array, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,5 +63,15 @@ namespace SDL
|
||||||
|
|
||||||
return new SDLPointerArray<T>(array, count);
|
return new SDLPointerArray<T>(array, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MustDisposeResource]
|
||||||
|
internal static SDLOpaquePointerArray<T>? CreateOpaque<T>(T** array, int count)
|
||||||
|
where T : unmanaged
|
||||||
|
{
|
||||||
|
if (array == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new SDLOpaquePointerArray<T>(array, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace SDL
|
||||||
|
{
|
||||||
|
[MustDisposeResource]
|
||||||
|
public sealed unsafe class SDLOpaquePointerArray<T> : IDisposable
|
||||||
|
where T : unmanaged
|
||||||
|
{
|
||||||
|
private readonly T** array;
|
||||||
|
public readonly int Count;
|
||||||
|
private bool isDisposed;
|
||||||
|
|
||||||
|
internal SDLOpaquePointerArray(T** array, int count)
|
||||||
|
{
|
||||||
|
this.array = array;
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T* this[int index]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
ObjectDisposedException.ThrowIf(isDisposed, this);
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegative(index);
|
||||||
|
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
|
||||||
|
Debug.Assert(array[index] != null);
|
||||||
|
return array[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (isDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isDisposed = true;
|
||||||
|
|
||||||
|
SDL3.SDL_free(array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue