Skip to content

fix(enums): harden EnumValues key resolution and lookup#97

Merged
VPDPersonal merged 3 commits into
mainfrom
fix/enum-values-key-resolution
Jul 3, 2026
Merged

fix(enums): harden EnumValues key resolution and lookup#97
VPDPersonal merged 3 commits into
mainfrom
fix/enum-values-key-resolution

Conversation

@VPDPersonal

@VPDPersonal VPDPersonal commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

🐛 Bug fixes in EnumValues<TValue> / EnumValue<TValue>

Bug Fix
Unresolved/type-mismatched key crashed Equals/GetValue (HasFlag on null or on a different enum type) Guard before calling HasFlag; fall back gracefully instead of throwing
Resolved-key cache never invalidated after Inspector edits (e.g. "Populate Missing Enum Members" left new rows unresolved) EnumValues<TValue> now implements ISerializationCallbackReceiver and invalidates the cache on every Inspector edit
EnumValue.Initialize kept a stale Key from a previous enum type after a failed parse Resets Key to null on failed parse
Unconfigured _enumType threw instead of falling back to the default value Falls back to default gracefully
[Flags] lookup used first-match-in-order, so a plain flag entry could shadow a more specific composite entry (easy to trigger via "Populate Missing Enum Members", which appends members in ascending value order) GetValue now prioritizes an exact-key match over a broader "contains" match

🛠️ Editor drawer hardening

  • EnumValuePropertyDrawer / EnumValuesPropertyDrawer now re-resolve SerializedProperty by path instead of holding references across closures — prevents ObjectDisposedException on list reorder/delete.

✨ Misc

  • Added StringExtensions.ToKebabCase, used for a valid VisualElement name instead of the nicified, space-containing displayName.
  • Marked _enumType as [TypeSelector(Required = true)].
  • Cleaned up/commented EnumValues.uss.

Notes for review

✅ All correctness fixes were reproduced and verified against the real bug (not just typechecked) by driving the actual Unity Editor via unicli Eval:
constructed SerializedObject/SerializedProperty scenarios that previously threw, confirmed the crash, applied the fix, then re-ran the same scenario to confirm it no longer throws.

Linked issues

- Re-resolve SerializedProperty by path instead of holding stale references in
  the EnumValue/EnumValues drawers, preventing ObjectDisposedException on list
  reorder/delete
- Invalidate EnumValues<T>'s resolved-key cache via ISerializationCallbackReceiver
  after Inspector edits, and reset a key that fails to re-parse, fixing
  stale/mismatched Key crashes across enum type changes
- Guard GetValue/Equals/GetEnumerator against unresolved or unconfigured enum
  types instead of throwing, and prioritize exact-key over partial "contains"
  matches for [Flags] lookups
- Add StringExtensions.ToKebabCase for element naming, mark _enumType as
  Required, and document the EnumValues.uss layout overrides
…events

- PropertyField only forwards UI-driven ChangeEvents from custom drawers, so a type picked via the TypeSelector window (a direct SerializedProperty write) never triggered UpdateValues and rows kept rendering the old enum
- track _enumType with TrackPropertyValue in both EnumValues/EnumValue drawers; drop the hidden per-row _enumType PropertyField that existed only as an event source
@VPDPersonal VPDPersonal marked this pull request as ready for review July 3, 2026 13:36
@VPDPersonal VPDPersonal merged commit 252c82a into main Jul 3, 2026
3 checks passed
@VPDPersonal VPDPersonal deleted the fix/enum-values-key-resolution branch July 3, 2026 13:36
@github-actions github-actions Bot added status: needs-review Ready for review and removed status: work-in-progress Draft / not ready for review status: needs-review Ready for review labels Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: editor Editor-only code area: runtime Runtime / player code type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant