Skip to content

fix: new ArenaTopics() leaves every segment null, so topic segment access throws #192

Open

Description

@claude

Runtime/ArenaTopics.cs:29 declares

public readonly struct ArenaTopics

and its constructor at :39-62 takes ten arguments that all default to "". That is not the parameterless constructor: new ArenaTopics() (and default(ArenaTopics)) zero-initializes the struct, so REALM, nameSpace, sceneName … (:63-72) come out null, not empty string. The default arguments are unreachable through that syntax.

The interpolated getters (:78-108) still produce well-shaped strings, because $"…" renders a null as empty — which is exactly what hides the problem. Any caller touching a segment directly gets a NullReferenceException from a value that looks default-constructed.

Observed

Runtime/ArenaTopics.cs compile-linked and run on .NET 8:

new ArenaTopics():
  REALM==null: True, nameSpace==null: True, sceneName==null: True, idTag==null: True

new ArenaTopics().PUB_SCENE_OBJECTS   => "/s///o//"        (renders fine, hides the nulls)
new ArenaTopics().nameSpace.Length    => System.NullReferenceException
new ArenaTopics().sceneName.StartsWith("x") => System.NullReferenceException

new ArenaTopics("").nameSpace.Length  => 0                 (the ctor path is fine)

So it is specifically the parameterless path that is unsafe; passing even one argument runs the constructor and the remaining defaults apply.

Fix options

  • coalesce in the property getters (get { return _nameSpace ?? ""; }), which fixes default(ArenaTopics) too — the only option that closes the hole completely for a struct;
  • make the type a class, so there is a real parameterless constructor to run;
  • or keep it as-is, add a static ArenaTopics.Empty built through the constructor, and document that new ArenaTopics() is not it.

#183 pins the current behaviour in Tests~/DotNet/ArenaUnity.PureTests/ArenaTopicsTests.cs with three Is.Null assertions; those flip if the coalescing option is chosen.


Generated by Claude Code

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions