Skip to content

fix: prevent OnPerformanceTickData from sending data on null #614

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 1 commit into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,7 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)

private void OnNetworkEarlyUpdate()
Copy link
Contributor

Choose a reason for hiding this comment

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

Deja Vu! Wasn't this another PR, no?

Copy link
Contributor Author

@kvassall-unity kvassall-unity Mar 15, 2021

Choose a reason for hiding this comment

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

Yes i was in a pr merged already to develop. But since its a ship blocker we need this pr in release. (this was before i knew we were merging downwards and not updwards)

{
PerformanceDataManager.BeginNewTick();
if (NetworkConfig.NetworkTransport is ITransportProfilerData profileTransport)
{
profileTransport.BeginNewTick();
}
ProfilerBeginTick();

if (IsListening)
{
Expand Down Expand Up @@ -760,13 +756,7 @@ private void OnNetworkPreUpdate()
}
}

if (NetworkConfig.NetworkTransport is ITransportProfilerData profileTransport)
{
var transportProfilerData = profileTransport.GetTransportProfilerData();
PerformanceDataManager.AddTransportData(transportProfilerData);
}

OnPerformanceDataEvent?.Invoke(PerformanceDataManager.GetData());
NotifyProfilerListeners();
}

internal void UpdateNetworkTime(ulong clientId, float netTime, float receiveTime, bool warp = false)
Expand Down Expand Up @@ -1495,5 +1485,37 @@ internal void HandleApproval(ulong clientId, bool createPlayerObject, ulong? pla
NetworkConfig.NetworkTransport.DisconnectRemoteClient(clientId);
}
}

private void ProfilerBeginTick()
{
PerformanceDataManager.BeginNewTick();
if (NetworkConfig.NetworkTransport is ITransportProfilerData profileTransport)
{
profileTransport.BeginNewTick();
}
}

private void NotifyProfilerListeners()
{
var data = PerformanceDataManager.GetData();
var eventHandler = OnPerformanceDataEvent;
if (eventHandler != null)
{
if (data != null)
{
if (NetworkConfig.NetworkTransport is ITransportProfilerData profileTransport)
{
var transportProfilerData = profileTransport.GetTransportProfilerData();
PerformanceDataManager.AddTransportData(transportProfilerData);
}

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