-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
refactor(NetworkManagerGUI): prevent potential NRE spam if reference is lost and tidy up #1130
Conversation
Somehow NMGUI can lose references for some reason, so short-circuit to prevent log spam.
"Add parentheses for clarity"
If auto configure is set but NetworkManager field is not null, then don't do anything.
Remove regions as per James request
// Is this STILL null? Then we throw in the towel and go home. | ||
if (NetworkManager == null) | ||
{ | ||
throw new ArgumentNullException("NetworkManager", $"You requested automatic configuration for the NetworkManagerGUI component on '{gameObject.name}'" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be InvalidOperationException
instead of Argument
// Coburn, 2023-01-29: | ||
// If automatic configuration of NetworkManager is enabled, then attempt to grab the | ||
// NetworkManager that this script is attached to. | ||
if (AutoConfigureNetworkManager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it hard to follow this chain of if/else,, would be better to do early returns instead
{ | ||
if (logger.logEnabled) | ||
{ | ||
logger.LogWarning($"You have enabled Auto Configure for this NetworkManagerGUI component on '{gameObject.name}' but the NetworkManager field is already set. " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need this warning.
🎉 This PR is included in version 129.6.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
While chasing a ghost error due to Unity adding two NetworkManagerGUIs to one object and I forgot to check that, I discovered that the component and spam NREs in its OnGUI loop.
So, what this PR does is quite a fair bit actually...
ArgumentNullException
and tell them to fix it. However, I have implemented it so if you do specify a NetworkManager reference and leave it ticked to automatically configure itself that it will not override your manual reference.As an added bonus, it also addresses Visual Studio complaining about IDE0048: "Add parentheses for clarity" by... you name it, adding parentheses around some Rect math.
Mirage. Makin' NetworkManageGUI great again.