Skip to content

Conversation

AlexTyrer
Copy link
Contributor

@AlexTyrer AlexTyrer commented Sep 30, 2024

Description

Most device decriptor fields are null-checked in ComparePropertyToDeviceDescriptor, however the addition of MakeEscapedJsonString meant that 'capabilities' was not being checked anymore, and so could throw a null-ref exception if a device didn't fill this field.

Changes made

This change adds a null/empty string check to MakeEscapedJsonString to mirror the old behaviour.
Additionally this'll also now mean any devices with an empty non-null string can skip a minor StringBuilder allocation.

Testing

Local testing with gamepads to see that the resulting comparisons in ComparePropertyToDeviceDescriptor still work correctly. This was tested between null, empty, and valid json string inputs.

A new unit test has been added too to exercise the null-input path.
Unit tests were also ran.

Risk

Minor difference in construction of a default JsonString (with a non-null text field).

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

…rings also now bypass an allocation.

This matches older behaviour on null-checking descriptor fields which is needed for certain device implementations.
@AlexTyrer AlexTyrer changed the title [Input System] MakeEscapedJsonString now null-checks inputs. Empty strings also now bypass an allocation. FIX: MakeEscapedJsonString now null-checks inputs. Empty strings also now bypass an allocation. Sep 30, 2024
@AlexTyrer AlexTyrer requested a review from lyndon-unity October 1, 2024 11:27
@AlexTyrer
Copy link
Contributor Author

Thanks to @stuartbrown-unity for the fix!

Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks safe - good to see it fixed the allocation count part too.

@AlexTyrer AlexTyrer merged commit 3a96dac into develop Oct 1, 2024
77 checks passed
@AlexTyrer AlexTyrer deleted the fix-exception-on-device-reconnect branch October 1, 2024 16:52
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.

2 participants