Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct FieldData de/serialization #798

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

Starlight220
Copy link
Member

@Starlight220 Starlight220 commented Mar 15, 2024

The first commit fixes #797
The second commit is a bug I saw and decided to fix on the way


The fix here is to explicitly check for the type being double[] and warning+dropping if not, rather than unsafely casting which leads to CCEs like #797 in cases where there's unrelated data in that table.

@PeterJohnson
Copy link
Member

Note that next year we will probably change things to publish a Pose2d struct instead.

@Starlight220
Copy link
Member Author

That can easily and non-breakingly be done by adding another else if clause to the deserialization.
And if we're already changing the schema, it should probably include an objects: string[] entry at the root table so the impl doesn't need to scan everything.

@Starlight220
Copy link
Member Author

I have reproduced the issue with main, and confirmed that the issue does not reproduce with a build from this branch.
My test code was the ramsetecontroller example, with the following modification:

diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java
index ef73d106d..8a1a1bcb7 100644
--- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java
+++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java
@@ -53,7 +53,8 @@ public class Robot extends TimedRobot {

     // Create and push Field2d to SmartDashboard.
     m_field = new Field2d();
-    SmartDashboard.putData(m_field);
+    SmartDashboard.putData("myfield", m_field);
+    SmartDashboard.putNumber("myfield/spam", 42);

     // Push the trajectory to Field2d.
     m_field.getObject("traj").setTrajectory(m_trajectory);

@PeterJohnson PeterJohnson merged commit 0e49f00 into wpilibsuite:main Apr 4, 2024
9 checks passed
@Starlight220 Starlight220 deleted the field-data branch April 5, 2024 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Field2d widget causes exception every frame
2 participants