spine-runtimes/todos/done/2025-01-21-19-06-33-circular-reference-display.md
Mario Zechner 6f81d43faa [cpp] Enhance circular reference display with deterministic object identifiers
Replace "<circular>" with meaningful reference strings using a hybrid approach:
- Objects with names: <EventData-walk>, <BoneData-head>, <Animation-run>
- Objects without names: <TrackEntry-1>, <Bone-2>, <SliderTimeline-3>

Each serialized object now includes "refString" as its first field, enabling
easy navigation from circular references to full object definitions.
2025-07-22 02:09:01 +02:00

2.9 KiB

Circular Reference Display Enhancement

Status: Done Agent PID: 67832

Original Todo

should include the type and a unique id for the object, so i can quckly understand what's been omitted navigate to it

Description

Replace "" with deterministic object identifiers in Spine serializers. The implementation uses a hybrid approach: objects with name properties use "" format (e.g. ""), while objects without names use numbered IDs "", "", etc. This ensures identical output across Java/C++ by using deterministic reference strings that are generated only when objects are first encountered.

Implementation Plan

  • Update Java generator script - Modified tests/src/generate-java-serializer.ts to use Map<Object, String> visitedObjects with nextId counter, generating name-based or numbered reference strings
  • Update C++ generator script - Modified tests/src/generate-cpp-serializer.ts to use HashMap<void*, String> with _nextId counter, matching Java logic with proper Spine String API usage
  • Regenerate serializers - Generated updated Java and C++ SkeletonSerializer classes with new circular reference handling
  • Fix deterministic IDs - Implemented hybrid system: <Type-name> for named objects, <Type-N> for unnamed objects, ensuring identical output across languages
  • Update test runner - Test runner handles new circular reference format correctly
  • Automated test: Serialization tests pass with no regressions
  • User test: Circular references now show meaningful format like <EventData-walk> or <Animation-1> instead of <circular>
  • Add reference string field: Include refString as first field in each object's JSON to enable quick navigation from circular references to full objects

Notes

Implementation Details:

  • Circular Reference Logic: Changed from simple boolean tracking to String-based reference storage
  • Reference String Generation: Only occurs when object is first encountered (after cycle detection check)
  • Name Detection: Uses p.getter === 'getName()' && p.valueType === 'String' to identify objects with meaningful names
  • Deterministic Numbering: Both Java and C++ use identical counter logic, ensuring same numbered IDs for unnamed objects
  • Types with Names: BoneData, EventData, IkConstraintData, PathConstraintData, PhysicsConstraintData, Animation, and attachment types
  • Output Format:
    • Named: <EventData-walk>, <BoneData-head>, <Animation-run>
    • Unnamed: <TrackEntry-1>, <Bone-2>, <SliderTimeline-3>
  • Navigation Enhancement: Each serialized object includes "refString" as its first field, making it easy to jump from circular reference to full object definition

Commands:

  • tests/generate-serializers.sh -> generates the serializers
  • tests/test.sh cpp -s spineboy -f -> compiles and runs the tests, and outputs whether the generated json files are identical