-
Random Errors Occurring When Running Game in Eclipse
Greetings.
In order to improve my programming skills I am following Notch (Minecraft creator) creating a game he made over this past weekend called Prelude of the Chambered (called Escape during coding stages). I've been going well and getting the same results as he has but all of a sudden I am getting unexpected, random errors which Notch wasn't getting. This is stopping me from running the game.
I am getting no errors in my code, but when I press the mighty green run button, the following errors are appearing in the console.
Code :
Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: -6
at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
at com.mojang.escape.gui.Screen.render(Screen.java:34)
at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
at java.lang.Thread.run(Unknown Source)
I have no idea why they are appearing, and how to fix them.
Help would be greatly appreciated.
-
Re: Random Errors Occurring When Running Game in Eclipse
Have you looked at the lines in your code where the array index goes out of bounds and determined why it gets a bad value? What code is at line 34 in Screen.java? Or line 105 in EscapeComponent.java
-
Re: Random Errors Occurring When Running Game in Eclipse
If you have no idea where these errors are coming from, I really really encourage you to start out with something smaller.
The competition Notch wrote that game for was called Ludum Dare, and there were almost 600 other entrants- many of which were written in Java, and all of which were open source. I suggest you start with the basic tutorials first, then when you're comfortable with the basics, start playing with a more basic game from the competition. You don't get to be on Notch's level overnight, or just by playing with somebody else's code.
JavaPF- This makes at least three! :p :p :p
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
Have you looked at the lines in your code where the array index goes out of bounds and determined why it gets a bad value? What code is at line 34 in Screen.java? Or line 105 in EscapeComponent.java
I've had these parts of the code in there for a while, I'd run it and it would work, but all of a sudden these errors are popping up which is what I find so strange about it.
Code :
at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
Code :
at com.mojang.escape.gui.Screen.render(Screen.java:34)
viewport.render(game);
Code :
at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
screen.render(game);
Code :
at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
render();
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
pixels[x + y * width] = ...
What are the values of x, y and width when this statement is executed?
Could the value of the expression be -6?
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
What are the values of x, y and width when this statement is executed?
Could the value of the expression be -6?
This is the whole section.
Code :
for (int x=0; x<width; x++) {
double xd = (x-width/2.0)/height;
xd *= z;
int xx = (int) (xd + game.time*0.1)%7;
int yy = (int) (z + game.time*0.1)%7;
zBuffer[x+y*width] = z;
pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
}
-
Re: Random Errors Occurring When Running Game in Eclipse
Add a println just before the statement with the invalid index to print out the contents of all the variables used in the computing the index.
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
Add a println just before the statement with the invalid index to print out the contents of all the variables used in the computing the index.
That only causes more errors, unless I am stupid and I;m doing it wrong.
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
That only causes more errors, unless I am stupid and I;m doing it wrong.
I don't see how a println statement can cause errors.
Please copy and paste here the full text of the error messages.
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
I don't see how a println statement can cause errors.
Please copy and paste here the full text of the error messages.
I've posted all the errors on the first post and here is the specific version of each error and what line it is.
-
Re: Random Errors Occurring When Running Game in Eclipse
That error message was BEFORE you added the println. What about AFTER you added the println?
Where are the print outs of the values used in the line where the index value is wrong?
Did you add a println statement to the code to show the variables values?
What did it print out?
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
That error message was BEFORE you added the println. What about AFTER you added the println?
Where are the print outs of the values used in the line where the index value is wrong?
Did you add a println statement to the code to show the variables values?
What did it print out?
I put printIn on one of the lines.
CODE LINE Before:
Code :
pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
CODE LINE After:
Code :
printIn pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
ERRORS Before:
Code :
Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: -5
at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
at com.mojang.escape.gui.Screen.render(Screen.java:34)
at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
at java.lang.Thread.run(Unknown Source)
ERRORS After:
Code :
println cannot be resolved to a variable
at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
at com.mojang.escape.gui.Screen.render(Screen.java:34)
at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
at java.lang.Thread.run(Unknown Source)
-
Re: Random Errors Occurring When Running Game in Eclipse
println refers to the println method of the out variable in the System class.
You use it like this:
System.out.println("var=" + var); // print the value of var
You need to print out the values of the variables used to compute the index.
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
println refers to the println method of the out variable in the System class.
You use it like this:
System.out.println("var=" + var); // print the value of var
You need to print out the values of the variables used to compute the index.
Code :
System.out.println("var=" + var); // pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
Like so?
-
Re: Random Errors Occurring When Running Game in Eclipse
No. Comments do not cause anything to print out.
Do you know what a variable is?
Do you know what variables are being used to compute the indexes to the arrays?
Those are what you should print out. Show the variables values.
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
No. Comments do not cause anything to print out.
Do you know what a variable is?
Do you know what variables are being used to compute the indexes to the arrays?
Those are what you should print out. Show the variables values.
Urgh. Silly me. I see now. I will do now.
-
Re: Random Errors Occurring When Running Game in Eclipse
I understand what you are meaning for me to do, but I don't know how to put that in the code, from what I've tried I haven't been successful.
Would it be like, if my code was this?
Code :
pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
I'd make it this?
Code :
System.out.println(pixels[x + y * width] = Art.floors.pixels[xx + yy * 64]);
-
Re: Random Errors Occurring When Running Game in Eclipse
Do you know what a variable is?
Do you know what variables are being used to compute the indexes to the arrays?
Those are what you should print out. Show the variables' values.
The variables you should print out the values of are: x, y, width, xx and yy.
They are used to compute the indexes to the two arrays.
The index to an array is what is between the []s
What happened when you executed this statement?
Code :
System.out.println(pixels[x + y * width] = Art.floors.pixels[xx + yy * 64]);
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
Do you know what a variable is?
Do you know what variables are being used to compute the indexes to the arrays?
Those are what you should print out. Show the variables' values.
The variables you should print out the values of are: x, y, width, xx and yy.
They are used to compute the indexes to the two arrays.
The index to an array is what is between the []s
What happened when you executed this statement?
Code :
System.out.println(pixels[x + y * width] = Art.floors.pixels[xx + yy * 64]);
Instead I did,
Code :
System.out.println(x + y + " error");
A whole lost of random number errors came out, here are only a few from the huge list.
Quote:
168 error
169 error
170 error
171 error
172 error
173 error
174 error
175 error
176 error
177 error
-
Re: Random Errors Occurring When Running Game in Eclipse
Is there a reason you've been refusing to answer the questions you've been asked? Norm, you deserve a medal for your patience- but I'm not that patient.
Step through your program with a debugger, or add simple print statements like Norm suggested. Why are you using an assignment statement inside a print line?
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
System.out.println(x + y + " error");
The problem with the way this prints out is that you do NOT see the values of x and y. You see the sum of the variables.
Try this: System.out.println("x=" + x + ", y" + y);
What was the last values that printed out before you got the error:
ArrayIndexOutOfBoundsException: -5
Those last values are the ONLY values you are interested in. The others are not what you need to see.
-
Re: Random Errors Occurring When Running Game in Eclipse
Quote:
Originally Posted by
Norm
The problem with the way this prints out is that you do NOT see the values of x and y. You see the sum of the variables.
Try this: System.out.println("x=" + x + ", y" + y);
What was the last values that printed out before you got the error:
ArrayIndexOutOfBoundsException: -5
Those last values are the ONLY values you are interested in. The others are not what you need to see.
Using that, I got, once again a long list, here are some....
Code :
x=0, y0
x=1, y0
x=2, y0
x=3, y0
x=4, y0
x=5, y0
x=6, y0
x=7, y0
Code :
x=153, y13
x=154, y13
x=155, y13
x=156, y13
x=157, y13
x=158, y13
x=159, y13
-
Re: Random Errors Occurring When Running Game in Eclipse
What were the last values that printed out before you got the error:
ArrayIndexOutOfBoundsException: -5
Are you getting the error still?