Skip to content

fix: prevent OnPerformanceTickData from sending data on null #586

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

Merged
merged 5 commits into from
Mar 12, 2021

Conversation

kvassall-unity
Copy link
Contributor

@kvassall-unity kvassall-unity commented Mar 10, 2021

If something causes an exception it's possible that the profiler never allocates data. in these cases, there is no point in sending data outside of MLAPI

…er never allocates data. in these cases there is no point in rendering.
@0xFA11 0xFA11 changed the title bugfix: If something causes an exception its possible that the profil… fix: early-return from OnPerformanceTickData if tickData is null (hardening) Mar 11, 2021
Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

🚢

@kvassall-unity kvassall-unity force-pushed the feature/profiler_null_check branch from 1d42ee0 to 58693eb Compare March 11, 2021 02:11
if (NetworkConfig.NetworkTransport is ITransportProfilerData profileTransport)
var data = PerformanceDataManager.GetData();
var eventHandler = OnPerformanceDataEvent;
if (eventHandler != null && data!= null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you could warn and say "Did you forget to call RegisterMLAPIPerformanceEvent() first?"


OnPerformanceDataEvent?.Invoke(PerformanceDataManager.GetData());
eventHandler?.Invoke(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
eventHandler?.Invoke(data);
eventHandler.Invoke(data);

unnecessary null check.

Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

since things changed a lot after I approved, I'll take that back and re-review again.
also please update the PR title again matching the changes accordingly.

@kvassall-unity kvassall-unity changed the title fix: early-return from OnPerformanceTickData if tickData is null (hardening) fix: prevent OnPerformanceTickData from sending data on null Mar 11, 2021
}
else if (data == null)
{
NetworkLog.LogWarning("No data available. Did you forget to call PerformanceDataManager.BeginNewTick() first?");
Copy link
Contributor

Choose a reason for hiding this comment

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

Some suggestions for this log, in case it makes its way to users:

  • "No data available" should be more specific. "No performance data available." perhaps
  • "Did you forget to call..." this will confuse users because it's not something they are supposed to call. At least i think it should be made sure that this is an internal error, and not something they can necessarily fix

Copy link
Contributor

@0xFA11 0xFA11 Mar 11, 2021

Choose a reason for hiding this comment

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

minor: I'd also suggest string interpolation syntax and nameof operator here.

NetworkLog.LogWarning($"No data available. Did you forget to call {nameof(PerformanceDataManager)}.{nameof(PerformanceDataManager.BeginNewTick)}() first?");

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, that's worth a quick fix to use the future-proofed naming system. We've started to adopt that make make it our standard.

@0xFA11 0xFA11 requested review from 0xFA11 and removed request for 0xFA11 March 12, 2021 00:27
Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

I couldn't remove myself from the reviewers list, so here I'm approving it 😛

@mattwalsh-unity mattwalsh-unity enabled auto-merge (squash) March 12, 2021 00:53
@mattwalsh-unity mattwalsh-unity enabled auto-merge (squash) March 12, 2021 01:09
@mattwalsh-unity mattwalsh-unity merged commit 992354e into develop Mar 12, 2021
@mattwalsh-unity mattwalsh-unity deleted the feature/profiler_null_check branch March 12, 2021 01:26
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.

5 participants