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 syncreport crash caused by getting LocalClient index from ReplayConnection #20532
Conversation
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.
Could we use inline strings here? C# often doesn't handle addition properly when nulls are involved
17e4067
to
5580bbc
Compare
Ok, fixed Although in my test the previous version works normal |
it would be cleaner with the aforementioned inline strings https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated |
OpenRA.Game/Network/SyncReport.cs
Outdated
@@ -104,7 +104,8 @@ void GenerateSyncReport(Report report, IEnumerable<OrderManager.ClientOrder> ord | |||
|
|||
internal void DumpSyncReport(int frame) | |||
{ | |||
var reportName = "syncreport-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + "-" + orderManager.LocalClient.Index + ".log"; | |||
var reportIndex = orderManager.LocalClient == null ? "" : orderManager.LocalClient.Index.ToString(); | |||
var reportName = "syncreport-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + "-" + reportIndex + ".log"; |
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.
var reportName = "syncreport-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + "-" + reportIndex + ".log"; | |
var reportName = "syncreport-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + $"-{orderManager.LocalClient?.Index}.log"; |
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.
Why not interpolate the entire string?
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.
can't have strings in strings
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.
mb, it appears you actually can. I assumed c# wasn't smart enough.
So then yes, the whole line should be interpolated
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.
var reportName = "syncreport-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + "-" + reportIndex + ".log"; | |
var reportName = $"syncreport-{DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture)}-{orderManager.LocalClient?.Index}.log"; |
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.
$"syncreport-{DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture)}-{orderManager.LocalClient?.Index}.log"
works on dotnetfiddle.
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.
So something like
var reportName = "syncreport-" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture) + "-" + reportIndex + ".log"; | |
var timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmssZ", CultureInfo.InvariantCulture); | |
var reportName = $"syncreport-{timestamp}-{orderManager.LocalClient?.Index}.log"; |
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.
So something like
Changed to that, feels good.
5580bbc
to
39cc8d9
Compare
Fix syncreport crash caused by getting LocalClient index from ReplayConnection.
Crash reproduction: