Skip to content

Create SDL3 overloads that don't require use of unsafe #14

@nolife99

Description

@nolife99

Some of the generated bindings return a pointer when it could return a ref (like how SDL.CreateSurfaceFrom returns SDLSurface* but SDL.DestroySurface can take a ref SDLSurface). It is safe to return a ref as the pointers are guaranteed to be pinned. Or, for async support, you can wrap the pointers in a struct and pass the pointer in the struct to the p/invoke.

Using the below methods, all pointers can be converted into a ref and vice versa
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.asref?view=net-6.0#system-runtime-compilerservices-unsafe-asref-1(system-void*)
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.aspointer?view=net-6.0

Additionally, I would also suggest changing the ref parameters to ref readonly parameters if possible (prevents having to write more code to support the current restricted overloads)

I understand that the goal is to keep a minimal bindings library, however adding new overloads to support non-unsafe code helps in writing significantly less code (and having to add unsafe everywhere)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions