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

Utils.GetItemById(269, 270, 271) Returns null. #512

Closed loganizer405 closed 11 years ago

loganizer405 commented 11 years ago

If you Execute TShock.Utils.GetItemById(269) it will return NullReferenceException. I tried to do Item item = TShock.Utils.GetItemById(269) and it crashes saying NullReferenceException. Same with IDs 270 and 271.

hakusaro commented 11 years ago

Could you be more specific in your bug report, or lack thereof?

Lucas Nicodemus via Web

On Thu, Aug 15, 2013 at 9:17 AM, Logan Kramer notifications@github.comwrote:

If you Execute TShock.Utils.GetItemById(269) it doesnt work. Same wih 270 and 271.

— Reply to this email directly or view it on GitHubhttps://github.com/TShock/TShock/issues/512 .

loganizer405 commented 11 years ago

@nicatronTg Done.

Olink commented 11 years ago
public Item GetItemById(int id)
{
Item item = new Item();
item.netDefaults(id);
return item;
}

I don't quite see where we have a null, given that we new up the item. Are you sure it isnt YOUR code thats nre?

I dont have the option to test right now, and I dont want to sound like an asshole, but I have to question your understanding of computer science given your presence on the forums, and a quick look at your most recent plugin attempt where you check if the chat "/login xxxxxxxxx" happens and checking if they are logged in( 1. before tshock has a chance to look at it, 2.after tshock has handled it because we handle those chat events to prevent them from being sent to the players) Either way, I can't see that code ever working unless they type /login twice...

You will need to provide a snippet of your source where this happens if you want us to look into it.

loganizer405 commented 11 years ago

@Olink I made a console application to test this. static void Main() { Item item = TShock.Utils.GetItemById(269); Console.WriteLine(item.name); Console.ReadKey(); }
I get this: untitled2

Olink commented 11 years ago

Ignore previous comment, i forgot our utils singleton name is the same as the class, which is really confusing from a readability standpoint.

First off, why are you using tshock with a console application, we cant guarentee any sort of reliability when tshock is created from anything not our server api. Second off, your screenshot only shows us that

Item item = Tshock.Utils.GetItemByID(269);

has a null somewhere in it, not our method, which means your TShock instance is null, your Utils instance is null.

loganizer405 commented 11 years ago

@Olink Well I don't think they are null because it work with ever other ID except 269/270/271. Unless I'm just stupid and don't understand that :\ Even inside my plugin, this doesn't work. To test things, I just use a console application(Don't know why). And if I do this: Item item = new Item(); item = TShock.Utils.GetItemById(269); Still nothing

hakusaro commented 11 years ago

You can't access it if it isn't on...

Lucas Nicodemus via Google Nexus 4 On Aug 15, 2013 10:57 AM, "Logan Kramer" notifications@github.com wrote:

@Olink https://github.com/Olink Well I don't think they are null because it work with ever other ID except 269/270/271. Unless I'm just stupid and don't understand that :\ Even inside my plugin, this doesn't work. To test things, I just use a console application(Don't know why).

— Reply to this email directly or view it on GitHubhttps://github.com/TShock/TShock/issues/512#issuecomment-22713537 .

Olink commented 11 years ago

Second off, your screenshot only shows us that

Item item = Tshock.Utils.GetItemByID(269);

has a null somewhere in it, not our method, which means your TShock instance is null, your Utils instance is null.

Again, we dont support what you are doing, reproduce it in a plugin environment and we can talk.

k0rd commented 11 years ago

probably caused by these particular items' color being set like this in the server code: this.color = Main.player[Main.myPlayer].shirtColor;

(these are the familiar shirt, pants, wig)

Olink commented 11 years ago

@k0rd who do you think you are, posting once in a blue moon (jk)

loganizer405 commented 11 years ago

@Olink Seems like It's not my problem then....

k0rd commented 11 years ago

ha! I didn't mean to imply that.

Running from a console application could easily lead to Main.myPlayer returning a value that isn't expected. As (I imagine) spawning from a console could (the latter is just speculation.)

For this issue, trace output from a real plugin - or access to plugin source - could help us to determine the real cause and possible solutions. We cannot accept an unsupported 'test' implementation as concept.

[edit] also olink, not sure who i am anymore.. sad, huh?

hakusaro commented 11 years ago

TShock directly calls methods in the server API, which doesn't exist if the server isn't running. There is no doubt in my mind that this method of accessing TShock would not only have a high likelihood of failure, but would instead be guaranteed to fail.

Lucas Nicodemus via Google Nexus 4 On Aug 15, 2013 7:15 PM, "k0rd" notifications@github.com wrote:

ha! I didn't mean to imply that.

Running from a console application could easily lead to Main.myPlayer returning a value that isn't expected. As (I imagine) spawning from a console could (the latter is just speculation.)

For this issue, trace output from a real plugin - or access to plugin source - could help us to determine the real cause and possible solutions. We cannot accept an unsupported 'test' implementation as concept.

— Reply to this email directly or view it on GitHubhttps://github.com/TShock/TShock/issues/512#issuecomment-22742226 .

Olink commented 11 years ago

@loganizer405 Seems like it is, since you have yet to prove to us that in game, /item xxx fails for a null pointer somewhere IN Tshock, not in your fucked up implementation.

@k0rd its okay, soon 1.2 and you can have a justified reason to work on tshock again ;)

k0rd commented 11 years ago

@Olink - I have a feeling we're gonna have a lot of stuff to do :) should be fun!

loganizer405 commented 11 years ago

@Olink The reason its not working is because I was running a for loop to get a list of items. And since that is not executed by the player, the color thing k0rd was talking about returns null.

k0rd commented 11 years ago

@loganizer405 I'm pretty sure that's what he's been trying to tell you this whole time.

loganizer405 commented 11 years ago

@k0rd i guess so. At least i finally figured out what it was :|