Pryaxis / TShock

☕️⚡️TShock provides Terraria servers with server-side characters, anti-cheat, and community management tools.
GNU General Public License v3.0
2.43k stars 382 forks source link

CurrentRegion nullReferenceException #876

Closed Zaicon closed 9 years ago

Zaicon commented 9 years ago

Trying to access a TSPlayer's CurrentRegion info (Name, Owner, etc) needs to throw a NullReferenceException (at least a Warning, anyway) if a player isn't in any region. Right now, it just fails silently, and it took me a while to figure out what the cause was.

Olink commented 9 years ago

CurrentRegion is not a method, it is a field, and as such, when null, means they are not in a current region. What exactly do you want from it?

Zaicon commented 9 years ago

In a plugin, I made a check to see if TShock.Players[i].CurrentRegion.Name == whatever region.

Since CurrentRegion was null at that given time, it obviously couldn't complete the check. Instead of throwing a null reference exception (which is what TShock does every other time a plugin tries to reference a field of a null class), it just didn't do anything and didn't give me any error messages.

Olink commented 9 years ago

Uhhh, do you even know how to program? TShock does not throw any exceptions, thats the runtime. If you did that and there was no null exception as expected, then 1) You have a try/catch surrounding the code and swallowed the exception, not our problem. 2) You assume that the CurrentRegion is null, when it isnt, which isn't our problem, again.

So far you havn't really given me any reason to think that the current implementation is broken.