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

FIX: Potential NullReferenceException in UnregisterCallbacks() #1666

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Kevinsomnia
Copy link

Description

A callback interface can get destroyed and lead to a missing reference within the InputActions callbacks list. If SetCallbacks() is called afterwards, it can attempt to unregister null entries within the list, leading to a NullReferenceException.

Changes made

Added a null check at the top of UnregisterCallbacks().
Ran unit tests and updated auto-generated code in the Unity project.

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.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • 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.

For example, when a callback interface gets destroyed and the reference becomes null.
@unity-cla-assistant
Copy link

unity-cla-assistant commented Apr 1, 2023

CLA assistant check
All committers have signed the CLA.

@jfreire-unity jfreire-unity added the waiting-for-review The issue is scheduled to be reviewed by the Unity maintainers label Apr 12, 2023
@ekcoh
Copy link
Collaborator

ekcoh commented Sep 29, 2023

Thanks for this suggested bug fix PR @Kevinsomnia. I am curious though if it's what we would like to solve this issue since invoking those functions with null in general would not be a common or recommended operation. It could make more sense to avoid invoking these methods will null in the first place. Not sure I understood exactly where the SetCallbacks(null) calls were originating from, do you have more information on that? It would likely be better to avoid calling SetCallbacks(null) in the first place or is there something I am not really understanding here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-review The issue is scheduled to be reviewed by the Unity maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants