Skip to content

Development - #18

Merged
Blizzardo1 merged 7 commits into
mainfrom
development
Jun 1, 2026
Merged

Development#18
Blizzardo1 merged 7 commits into
mainfrom
development

Conversation

@Blizzardo1

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 1, 2026 07:29

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Blizzardo1, your pull request is larger than the review limit of 150000 diff characters

Signed-off-by: Adonis Deliannis <blizzardo1@blizzeta.net>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SharpSDL3’s C# bindings with a broad set of wrapper refactors (primarily local-variable typing modernizations) and introduces/adjusts some public-surface items (exception type + docs), alongside a library target framework bump.

Changes:

  • Refactors SDL_ttf wrapper code in Ttf.cs (e.g., var usage, explicit struct initialization in out paths).
  • Bumps SharpSDL3 target framework to net10.0.
  • Adds/updates public API documentation elements (SdlException docs, Colorspace XML docs).

Reviewed changes

Copilot reviewed 35 out of 44 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
SDL3/TTF/Ttf.cs Refactors SDL_ttf wrapper code; includes a version-query method with a correctness issue.
SDL3/SDL/Tray.cs Updates tray entry enumeration logic; currently returns incorrect results.
SDL3/SharpSDL3.csproj Updates library target framework; introduces test/build incompatibility with net9.0 tests.
SDL3/SDL/SdlException.cs Introduces SdlException; XML docs currently misdescribe its scope.
SDL3/Enums/Colorspace.cs Updates enum docs; includes a small typo in a summary line.
Comments suppressed due to low confidence (3)

SDL3/SDL/Tray.cs:146

  • GetTrayEntries() copies the native entries into the managed entries array, but then returns a Span created from ref result (a single element containing the pointer value) and ToArray() of that. This returns incorrect data and effectively ignores the copied entries.
    SDL3/TTF/Ttf.cs:996
  • GetHarfBuzzVersion() reads major/minor/patch from the allocated pointers before calling TTF_GetHarfBuzzVersion, so it returns uninitialized data and the subsequent zero-check is unreliable.
    SDL3/SDL/Tray.cs:144
  • GetTrayEntries() copies the native entries into the managed entries array, but then returns a Span created from ref result (a single element containing the pointer value) and ToArray() of that. This returns incorrect data and ignores the copied entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SDL3/SharpSDL3.csproj
Comment thread SDL3/Enums/Colorspace.cs
Comment thread SDL3/SharpSDL3.csproj
Comment thread SDL3/TTF/Ttf.cs
Comment thread SDL3/Enums/Colorspace.cs Outdated
Blizzardo1 and others added 2 commits June 1, 2026 00:36
Signed-off-by: Adonis Deliannis <blizzardo1@blizzeta.net>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adonis Deliannis <blizzardo1@blizzeta.net>
Copilot AI review requested due to automatic review settings June 1, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 44 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (22)

SDL3/SDL/Tray.cs:146

  • GetTrayEntries allocates and fills an entries array, but then ignores it and instead constructs a Span over result (the pointer variable) via new Span<IntPtr>(ref result). This either won’t compile (missing length overload) or will return only a single element (the pointer value) rather than the actual tray entries.
    SDL3/TTF/Ttf.cs:1001
  • GetHarfBuzzVersion reads from the allocated buffers before calling TTF_GetHarfBuzzVersion, so major/minor/patch will be uninitialized/garbage. Call the native function first, then read the values, and ensure the allocations are freed via try/finally.
    SDL3/TTF/Ttf.cs:1692
  • GetTextSubStringsForRange can dereference pSubStrings even when it is nint.Zero (it only logs and continues). Also, pCount is allocated with Malloc (uninitialized), so on failure count may become garbage. Initialize pCount to 0 and return an empty array when the native call fails or returns no substrings.
    SDL3/SDL/IO.cs:45
  • GetIoSize throws when the size is 0, but SDL returns a negative value on failure and 0 is a valid size (e.g., an empty stream). This will incorrectly throw for empty files/streams.
    SDL3/SDL/IO.cs:60
  • GetIoStatus currently throws when the returned status value is 0, but IoStatus.Ready is defined as 0. This makes GetIoStatus unusable on the most common path. It should return the status directly (and let callers decide how to handle IoStatus.Error).
    SDL3/SDL/Tray.cs:146
  • GetTrayEntries allocates and fills an entries array, but then ignores it and instead constructs a Span over result (the pointer variable) via new Span<IntPtr>(ref result). This either won’t compile (missing length overload) or will return only a single element (the pointer value) rather than the actual tray entries.
    SDL3/TTF/Ttf.cs:1001
  • GetHarfBuzzVersion reads from the allocated buffers before calling TTF_GetHarfBuzzVersion, so major/minor/patch will be uninitialized/garbage. Call the native function first, then read the values, and ensure the allocations are freed via try/finally.
    SDL3/TTF/Ttf.cs:1692
  • GetTextSubStringsForRange can dereference pSubStrings even when it is nint.Zero (it only logs and continues). Also, pCount is allocated with Malloc (uninitialized), so on failure count may become garbage. Initialize pCount to 0 and return an empty array when the native call fails or returns no substrings.
    SDL3/SDL/IO.cs:45
  • GetIoSize throws when the size is 0, but SDL returns a negative value on failure and 0 is a valid size (e.g., an empty stream). This will incorrectly throw for empty files/streams.
    SDL3/SDL/IO.cs:60
  • GetIoStatus currently throws when the returned status value is 0, but IoStatus.Ready is defined as 0. This makes GetIoStatus unusable on the most common path. It should return the status directly (and let callers decide how to handle IoStatus.Error).
    SDL3/SDL/Touch.cs:51
  • GetTouchDevices returns a managed copy of the array but never frees the native buffer, even though the XML docs state it "should be freed with Free". This leaks unmanaged memory on every call.
    SDL3/SDL/Touch.cs:90
  • GetTouchFingers(ulong touchId) returns a managed copy but never frees the native allocation, despite the docs explicitly saying it must be freed with Free. This leaks unmanaged memory.
    SDL3/SDL/Touch.cs:111
  • GetTouchFingers(ulong touchId, out int count) returns a managed copy but never frees the native allocation, despite the docs explicitly saying it must be freed with Free. This leaks unmanaged memory.
    SDL3/SDL/Camera.cs:227
  • GetCameras copies the returned IDs into managed memory but never frees the native array, even though the docs state it "should be freed with Free". This leaks unmanaged memory each call.
    SDL3/SDL/Camera.cs:266
  • GetCameraSupportedFormats copies the returned pointers into managed memory but never frees the native array, even though the docs state it "should be freed with Free". This leaks unmanaged memory each call.
    SDL3/SDL/JoySticks.cs:596
  • GetJoysticks has multiple issues: (1) it initializes List<nint> with new List<IntPtr>(count) which is a generic type mismatch and may not compile; (2) it uses i * nint.Size as the element stride while reading 32-bit values via ReadInt32, which will produce wrong offsets on 64-bit; and (3) it never frees the native array even though the docs say it must be freed with Free.
    SDL3/SDL/Touch.cs:51
  • GetTouchDevices returns a managed copy of the array but never frees the native buffer, even though the XML docs state it "should be freed with Free". This leaks unmanaged memory on every call.
    SDL3/SDL/Touch.cs:90
  • GetTouchFingers(ulong touchId) returns a managed copy but never frees the native allocation, despite the docs explicitly saying it must be freed with Free. This leaks unmanaged memory.
    SDL3/SDL/Touch.cs:111
  • GetTouchFingers(ulong touchId, out int count) returns a managed copy but never frees the native allocation, despite the docs explicitly saying it must be freed with Free. This leaks unmanaged memory.
    SDL3/SDL/Camera.cs:227
  • GetCameras copies the returned IDs into managed memory but never frees the native array, even though the docs state it "should be freed with Free". This leaks unmanaged memory each call.
    SDL3/SDL/Camera.cs:266
  • GetCameraSupportedFormats copies the returned pointers into managed memory but never frees the native array, even though the docs state it "should be freed with Free". This leaks unmanaged memory each call.
    SDL3/SDL/JoySticks.cs:596
  • GetJoysticks has multiple issues: (1) it initializes List<nint> with new List<IntPtr>(count) which is a generic type mismatch and may not compile; (2) it uses i * nint.Size as the element stride while reading 32-bit values via ReadInt32, which will produce wrong offsets on 64-bit; and (3) it never frees the native array even though the docs say it must be freed with Free.

Comment thread SDL3/SharpSDL3.csproj
Comment thread SDL3/SharpSDL3.csproj
Signed-off-by: Adonis Deliannis <blizzardo1@blizzeta.net>
Copilot AI review requested due to automatic review settings June 1, 2026 07:53
@Blizzardo1
Blizzardo1 removed the request for review from Copilot June 1, 2026 07:53
@Blizzardo1
Blizzardo1 merged commit 0083b56 into main Jun 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants