Skip to content

Getters that return pointers into shared thread-local storage #9

Description

@jcant0n

Several getters return const T* pointing at a thread_local snapshot rather than at the object's own data. A second call on the same thread overwrites the first result, so a = Get(x); b = Get(y); leaves both showing y.

Confirmed cases:

function what is shared
Skeleton_GetJoint joint->name and parentName point into two thread_local std::strings
Ragdoll_GetRagdollSettings returns &tl_rs, one static thread_local wrapper for every ragdoll
WheelSettingsWV_GetLongitudinalFriction / GetLateralFriction shared snapshot
WheeledVehicleController_GetTransmission and the settings equivalent shared snapshot

The const T* signature reads like a borrowed reference to live data. It is a copy with a lifetime of "until the next call on this thread", and nothing in the headers says so.

This bites hardest in a managed layer. A C# binding that copies the struct and marshals the strings later reads whichever name was fetched most recently — the failure is a wrong value, not a crash, and it will look like a data bug anywhere but here.

Ragdoll_GetRagdollSettings has a second edge: passing its result to RagdollSettings_Destroy would drop a reference the Ragdoll still owns. Only a comment prevents that today.

The tests in test_skeleton_extra.c and test_vehicle_extra.c read each result before the next call, which is a workaround rather than a fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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