fix: Fixed issue of RpcTarget not being properly disposed #3866
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose of this PR
This PR aims to resolve a memory leak issue reported in #3852
The bug was a memory leak in NetworkAnimator on clients due to RpcTarget not being properly disposed.
The cause of it was that in
NetworkAnimator.OnNetworkSpawn(), the code cast the result ofRpcTarget.Group()toRpcTargetGroup. On clients,RpcTarget.Group()returns aProxyRpcTargetGroup(notRpcTargetGroup), so the cast returned null. TheProxyRpcTargetGroupwith itsNativeList<ulong>(allocated withAllocator.Persistent) was then leaked.The fix was to change
m_TargetGroupto use theIGroupRpcTargetinterface (which bothRpcTargetGroupandProxyRpcTargetGroupimplement)By using IGroupRpcTarget (the interface both implement), m_TargetGroup can now hold:
The code only uses interface methods (Add(), Clear(), Target), so it works correctly regardless of which concrete class is stored.
Jira ticket
https://jira.unity3d.com/browse/UUM-133278
Changelog
NetworkAnimatoron clients whereRpcTargetgroups were not being properly disposed due to incorrect type casting ofProxyRpcTargetGrouptoRpcTargetGroup.Documentation
N/A
Testing & QA (How your changes can be verified during release Playtest)
I confirmed that when using latest
develop-2.0.0the issue was reproducible in the project but is not reproducible when using this branchBackports
N/A