Facepunch / sbox-issues

178 stars 12 forks source link

Array properties throw an error when trying to add new items #7090

Open Fortune117 opened 20 hours ago

Fortune117 commented 20 hours ago

Describe the bug

I have a very simple resource set up:

[GameResource("Face Connection", "fconn", "A connection from a submodule face.", Icon = "join_left")]
public class TestResource : GameResource
{
    public ConnectionData[] Connections { get; set; } = Array.Empty<ConnectionData>();
}

public class ConnectionData
{
    private int Number { get; set; }
}

This appears correctly in the editor but hitting the + button throws this error:

Collection was of a fixed size.
System.NotSupportedException: Collection was of a fixed size.
   at System.Array.System.Collections.IList.Insert(Int32 index, Object value)
   at Sandbox.SerializedList.Insert(Int32 index, Object value) in C:\build\_work\sbox\sbox\engine\Sandbox.System\SerializedObject\SerializedList.cs:line 80
   at Sandbox.SerializedList.Add(Object value) in C:\build\_work\sbox\sbox\engine\Sandbox.System\SerializedObject\SerializedList.cs:line 63
   at Editor.ListControlWidget.AddEntry() in C:\My Stuff\Steam\steamapps\common\sbox\addons\tools\Code\Widgets\ControlWidgets\ListControlWidget.cs:line 83
   at Editor.Widget.OnMouseClick(MouseEvent e) in C:\build\_work\sbox\sbox\engine\Sandbox.Tools\Qt\Widget.Events.cs:line 103
   at Editor.IconButton.OnMouseClick(MouseEvent e) in C:\build\_work\sbox\sbox\engine\Sandbox.Tools\Widgets\IconButton.cs:line 64
   at Editor.Widget.OnMouseReleased(MouseEvent e) in C:\build\_work\sbox\sbox\engine\Sandbox.Tools\Qt\Widget.Events.cs:line 75
   at Managed.SourceTools.Exports.Editor_Widget_InternalMouseReleaseEvent(UInt32 self, IntPtr e) in C:\build\_work\sbox\sbox\engine\Sandbox.Tools\Interop.Tools.cs:line 22633

To Reproduce

  1. Open the test repo
  2. Try adding a new element to the array in the resource
  3. Error

Expected behavior

Should work as expected!

Media/Files

bug_repo.zip

Additional context

No response

MrBrax commented 19 hours ago

is there a reason to not use a list here?

Fortune117 commented 13 hours ago

is there a reason to not use a list here?

A list would work instead, but the bug is about arrays.