Skip to content

Fix shared singleton mutation in OneTime bindable member Get methods#85

Open
VPDPersonal wants to merge 1 commit into
Version/Aspid.MVVM-1.1.0from
fix/one-time-bindable-member-singleton
Open

Fix shared singleton mutation in OneTime bindable member Get methods#85
VPDPersonal wants to merge 1 commit into
Version/Aspid.MVVM-1.1.0from
fix/one-time-bindable-member-singleton

Conversation

@VPDPersonal
Copy link
Copy Markdown
Owner

Summary

  • OneTimeBindableMember<T>.Get(), OneTimeStructBindableMember<T>.Get(), and OneTimeEnumBindableMember<T>.Get() all mutated a shared static _instance and returned it. Any caller that retained the reference across two Get() calls on the same type would silently observe the second value instead of the first.
  • Replaced the singleton pattern with fresh instance allocation per call. Value is now set via constructor rather than post-construction mutation, making each returned instance independently immutable.
  • Allocation cost is negligible: OneTime bindings fire exactly once per bind cycle, so this is a one-shot heap allocation per binding — identical in practice to what was already happening at bind time.

Notes for review

The Value property on OneTimeStructBindableMember<T, TBoxed> was changed from { get; private protected set; } to { get; } (init-only via constructor). This is a tighter contract that prevents any future accidental mutation from derived types.

No generated code changes are needed — the generator emits SomeType.Get(memberName) whose result is consumed immediately, so the fix is transparent.

Linked issues

N/A

… Get methods

Replace the per-type static singleton pattern with fresh instance creation
in Get(). The singleton's Value was mutated before being returned, so any
caller that held a reference across multiple Get() calls would observe stale
or incorrect values. Since OneTime bindings fire exactly once per bind cycle
the allocation cost is negligible, and the hazard is completely removed.
@VPDPersonal VPDPersonal added status: work-in-progress Draft / not ready for review type: fix Bug fix area: runtime Runtime / player code labels May 27, 2026
@VPDPersonal VPDPersonal marked this pull request as ready for review May 27, 2026 08:44
@github-actions github-actions Bot added status: needs-review Ready for review and removed status: work-in-progress Draft / not ready for review labels May 27, 2026
@VPDPersonal VPDPersonal added status: do-not-merge Do not merge regardless of approvals and removed status: needs-review Ready for review labels May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Runtime / player code status: do-not-merge Do not merge regardless of approvals type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant