Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schemafields that are supposed to return fix sized arrays #134

Open
KillStr3aK opened this issue Nov 25, 2023 · 2 comments
Open

Fix schemafields that are supposed to return fix sized arrays #134

KillStr3aK opened this issue Nov 25, 2023 · 2 comments
Labels
area-API-SchemaSystem Related to the Source 2 Schema System
Milestone

Comments

@KillStr3aK
Copy link
Contributor

KillStr3aK commented Nov 25, 2023

The current workaround is this:

public unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T: NativeObject
{
    nint ptr = pointer + Schema.GetSchemaOffset(@class, member);
    Span<nint> references = MemoryMarshal.CreateSpan<nint>(ref ptr, length);
    T[] values = new T[length];

    for (int i = 0; i < length; i++)
    {
        values[i] = (T)Activator.CreateInstance(typeof(T), references[i])!;
    }

    return values;
}

this works in general and can access the whole schemaclass but when I messed with viewmodels I've experienced a segfault when tried to access the animation? string and it was corrupted memory but haven't investigated further yet but this needs attention for sure.

I might take on this just to dont forget about the issue in general I've opened this

@roflmuffin roflmuffin added the area-API-SchemaSystem Related to the Source 2 Schema System label Dec 11, 2023
@roflmuffin roflmuffin added the untriaged New issue has not been triaged label Feb 22, 2024
@roflmuffin roflmuffin added this to the Future milestone Feb 22, 2024
@roflmuffin roflmuffin removed the untriaged New issue has not been triaged label Feb 24, 2024
@KillStr3aK
Copy link
Contributor Author

KillStr3aK commented Oct 8, 2024

Bumping this, the current implementation with Span<T> limits the usage of the API as it does not support any T that has a pointer or reference inside

Is there anything wrong with the mentioned workaround tho?

@KillStr3aK
Copy link
Contributor Author

When this will be worked on, lets not forget about #613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-API-SchemaSystem Related to the Source 2 Schema System
Projects
None yet
Development

No branches or pull requests

2 participants