Skip to content

Conversation

@niekschoemaker
Copy link
Contributor

Goal of this PR

This fixes an error if a null value is accidently passed into Debug.WriteLine

How is this PR achieving the goal

Using simple Null coalescing on the ToString call

This PR applies to the following area(s)

ScRT: C# v2

Successfully tested on

Tested the code seperate from the game, it prints nothing instead of causing a NullReferenceException.

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

@niekschoemaker
Copy link
Contributor Author

This is a somewhat opiniated change, so not sure which behavior is more desirable, printing nothing or Debug.WriteLine causing an Exception.

@github-actions github-actions bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Oct 19, 2024
@DaniGP17
Copy link
Contributor

Wouldn't it be better to print "null" instead of an empty string like in unity?

@niekschoemaker
Copy link
Contributor Author

niekschoemaker commented Oct 20, 2024

Wouldn't it be better to print "null" instead of an empty string like in unity?

Was thinking the same but would add some extra logic, and this reflects the default behavior of C#, Console.WriteLine(null) in C# prints nothing.

@DaniGP17
Copy link
Contributor

Ohh okay, I've been checking how it was done in V1 of C# and it doesn't have this problem because the function expects a string instead of an object, so if you want to print it yourself you have to do the .ToString() and therefore The error is in your code and not in the Debug.WriteLine function itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid Requires changes before it's considered valid and can be (re)triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants