Jump to content

[1.6.4]Crashing but only on server with getIcon (arrayindexoutofbounds)


skullywag

Recommended Posts

Hey all,

 

Not sure what wrong here but im getting a crash when trying to join the server I start from eclipse with my mod loaded. The crash:

 

java.lang.ArrayIndexOutOfBoundsException: 15
at spawnCrystals.BlockCustomSpawner.getIcon(BlockCustomSpawner.java:47)

 

now that method is literally 1 line, ill add the relevant parts from my block class below:

 

private Icon[] icons;

    public void registerIcons(IconRegister par1IconRegister)
{
	icons = new Icon[13];

	for(int i = 0; i < icons.length; i++)
	{
		icons[i] = par1IconRegister.registerIcon(spawnCrystals.modid + ":" + (this.getUnlocalizedName().substring(5)) + i);
	}
}

public Icon getIcon(int par1, int par2)
{
	return icons[par2];
}

 

anyone have any idea why this crashes on the getIcon method? Ive also made sure there are 13 metadata blocks in this block ID all numbered correctly when registered in my main class.

 

edit - hmm par2 does seem to be 15 for some reason on loading into the world....how strange...but only on a server???

Link to comment
Share on other sites

Metadata ranges from 0 to 15.

 

Your icon array ranges from 0 to 13.

 

Take a WILD guess.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ok I will, im guessing by your statement you think the icons = new Icon[13]; should be  icons = new Icon[15]; youd be wrong. Ive learned that this icon array needs to be the same number as you have of metadata block. Changing it to 15 causes the reverse error: arrayindexoutofbounds 13. Doing this also crashes the client mode. As stated this ONLY crashed on the server its fine on just the client as is.

Link to comment
Share on other sites

ok after some more debugging and backtracing ive discovered that one of my blocks is actually in the world (I have no idea why, i didnt put it there), doing this:

 

public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
    	System.out.println("META -" + par1IBlockAccess.getBlockMetadata(par2, par3, par4));
    	System.out.println("pos - " + par2 + "," + par3 + "," + par4);
        return this.getIcon(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4));
    }

 

results in

 

2014-01-21 01:27:46 [iNFO] [sTDOUT] META -15

2014-01-21 01:27:46 [iNFO] [sTDOUT] pos - -194,69,240

 

(I also printed out the blockID in another test and it is my custom blockID) which I take to mean one of my custom blocks has entered the world somehow, now as they are mob spawners im guessing theres a mob spawner at those coords, however my block/TE doesnt even mention blockMobSpawner or its tileentity and it shouldnt be referencing mine so how on earth did it get there, this is gonna end up being such a silly error by me I know it.

Link to comment
Share on other sites

2014-01-21 01:27:46 [iNFO] [sTDOUT] META -15

2014-01-21 01:27:46 [iNFO] [sTDOUT] pos - -194,69,240

 

Bingo.

 

What you should do in your getIcon method is check for out of bounds and return a default icon (icons[0] is a good choice, so is null) just in case something like this happens.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

"Goes to Minecraft Forge Forums for help with crashing mod, doesn't read crash report, problem was a common Java error that can be fixed in 5 seconds."

if (user.hasKnowledgeOfJava) {

    if (user.question.hasCode) {

        return interpetHelpfulResponse(user.getQuestion());

    } else {

        return "Could you post your code please?";

    }

} else {

    return "Learn some freaking Java!";

}

Link to comment
Share on other sites

It states I read the crash report in the OP if youd open your eyes. It also states it worked fine in CLIENT ONLY MODE, I wanted to know why when running on a server I was getting the wrong meta data returned for a block I hadnt even placed. Literally on server login Id crash with that error.

 

Turns out it was actually the world that was the issue and I had some left over ghost block or something (still dont know really). Killing the world and restarting got rid of part of the problem. So it might of seemed like a "common Java error" but it wasnt,  So before you open your mouth and add nothing comments to my threads use your brain.

Link to comment
Share on other sites

And if you put sanity checks in your getIcon function, you wouldn't have had the problem anyway. 8)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

and from now on I will, please bare in mind that none of the forge tutorials and none of the tutorials submitted by third parties (like wuppy for instance) show doing this in this particular method (unless im blind), I understand its good practice in all programming languages and from now on ill remember to do it wherever I can to avoid such issues, this is all a learning experience for me and when it works perfectly fine in the Client you can surely understand my confusion. I understood the error fully I just couldnt understand HOW it was happening. Youve helped me a few times Draco18s and for that im grateful, however the guy trying to belittle me on a public forum for no reason whatsoever is just petty and uncalled for and I will always defend myself against such "trolls" especially when looking at their post history they get stuck on the same simple things I was getting stuck on.

 

Anyways this lesson is learned, onto the next thing to learn.

Link to comment
Share on other sites

and from now on I will, please bare in mind that none of the forge tutorials and none of the tutorials submitted by third parties (like wuppy for instance) show doing this in this particular method (unless im blind)

 

I do.

 

https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/item/ItemArtifact.java

 

(See how I check for null, and if null, I return a default non-null icon)

 

I feel like I've got an array-based something somewhere, but I can't recall which mod that was offhand, much less which block or item.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.