Skip to content

Fixed array in structures shows incorrect values in VS debugger #84514

Open
@CXuesong

Description

@CXuesong

Description

I'm not sure whether this a general issue, but if you declare a fixed float array in a structure, while the runtime behavior is correct, it shows incorrect values in the VS debugger.

Via https://twitter.com/neuecc/status/1643807528986513409

Reproduction Steps

Code snippet

var v = new Vec3(10.1f, 999.9f, 42.3f);
Console.WriteLine(v);    // <-- breakpoint here

unsafe struct Vec3
{

    public fixed float mF32[4];

    public Vec3(float x, float y, float z)
    {
        mF32[0] = x;
        mF32[1] = y;
        mF32[2] = z;
    }

    public float X => mF32[0];

    public float Y => mF32[1];

    public float Z => mF32[2];

    /// <inheritdoc />
    public override string ToString()
        => $"{X}, {Y}, {Z}";

}

Expected behavior

Console output

10.1, 999.9, 42.3

If I set up breakpoint on the WriteLine statement, I should see v is {10.1, 999.9, 42.3} in "Locals" / "Watch" window.

Actual behavior

Console output (correct)

10.1, 999.9, 42.3

"Locals" window
image

"Watch" window
image

Interestingly, the values of v.Y and v.Z are shown correctly only if it's directly added to the "Watch" window.

Regression?

Seems not a regression. It reproduces on .NET Framework 4.8.

Known Workarounds

Referencing the expressions v.Y & v.Z directly in the "Watch" window yields the correct value.

Configuration

  • .NET SDK 6.0.14 / 8.0.0-alpha.1.23080.2
    • Any CPU (x64 runtime)
  • Visual Studio 17.6.0 Preview 2.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions