For Loop Silently Halting

I’m not exactly sure where to put this question but I’ve had issues with a for loop in my terrain generation code. Upon the camera entering a new boundary, the new terrain should be updated; however, the new terrain is not being generated at all. I’ve pinpointed the problem to a specific issue within my code:

[java]private double[][][] getTerrain(int x, int y, int z)
{
System.out.println(“Marker 1”);
int chunkSize = this.getPatchSize() - 1;
double[][][] temp = new double[chunkSize][chunkSize][chunkSize];

	for (int i = x * chunkSize; i < chunkSize * (x + 1); i++)
	{
		for (int j = y * chunkSize; j < chunkSize * (y + 1); j++)
		{
			for (int k = z * chunkSize; k < chunkSize * (z + 1); k++)
			{
                                    System.out.println("Marker 2: loop");
				//temp[i][j][k] = this.getNoise().noise(i, j, k); // this line silently ends the for loop
                                    temp[i][0][0] = 1; // this line also ends the for loop
			}
		}
	}
	
	return temp;
}[/java]

It seems that any getTerrain() call after the initial run will abruptly end once it gets to any line dealing with assigning values to the temp array. Successive getTerrain() method calls result in only one System.out.println() being used, unlike the expected 16 or so. getTerrain() itself is being called from the getWorldItem() method in code based off of that found here: https://github.com/jayfella/World

Interestingly enough, if you comment out the value assignments from temp then the loop will continue to iterate through, as seen through the feedback provided by the console.

If any of you can help me figure out what’s wrong (is it a threading issue?) I’ll be forever in your debt! :smiley:

Probably you got a null pointer exception because temp[i] has not been initialized.

[java]
double[][][] temp = new double[chunkSize][chunkSize][chunkSize];
[/java]

initializes temp but not temp[0]. For further information, consult any Java textbook.

I’m not actually getting any error but I do believe I should be getting an ArrayIndexOutOfBoundsException (my array index values are way off). Thanks though!

PLEASE DELETE/CLOSE THE TOPIC!

@mjbmitch said: I'm not actually getting *any* error but I do believe I should be getting an ArrayIndexOutOfBoundsException (my array index values are way off). Thanks though!

PLEASE DELETE/CLOSE THE TOPIC!

If you aren’t getting an error then it’s because logging is turned off of or something else is swallowing the error. For example, if ever in code you see something like:
catch( Exception e ) {}

…with no code in the {}… you pretty much have the world’s permission to kick that developer where it hurts.

By any chance is this code being run as the result of some action in a Nifty gui? Nifty in JME is pretty notorious for swallowing exceptions.

@sgold said: Probably you got a null pointer exception because temp[i] has not been initialized.

[java]
double[][][] temp = new double[chunkSize][chunkSize][chunkSize];
[/java]

initializes temp but not temp[0]. For further information, consult any Java textbook.

For primitive arrays, this is enough to fully initialize the array. You will not get NPEs from reading any index of this array… but OP’s code will certainly get index out of bounds exceptions.

I am not sure what’s swallowing up the error but I’ve checked the code for any empty catch statements and there are none. I’ve based my code on the code linked in the OP so you can take a look at it there.

I encountered another iteration (pun intended) of my errors being silenced after doing something that would’ve resulted in an ArrayIndexOutOfBoundsException in another area of the code but I was able to troubleshoot it fairly easily. I just want to know what’s causing it because it’s going to bite me in the ass if I can’t get feedback from errors in the future.

In case you are wondering, I do get run-time errors on occasion (just not in certain scenarios like those described), they just might be coming from a different area of the code (most likely from a different class entirely).

@mjbmitch said: I am not sure what's swallowing up the error but I've checked the code for any empty catch statements and there are none. I've based my code on the code linked in the OP so you can take a look at it there.

I encountered another iteration (pun intended) of my errors being silenced after doing something that would’ve resulted in an ArrayIndexOutOfBoundsException in another area of the code but I was able to troubleshoot it fairly easily. I just want to know what’s causing it because it’s going to bite me in the ass if I can’t get feedback from errors in the future.

In case you are wondering, I do get run-time errors on occasion (just not in certain scenarios like those described), they just might be coming from a different area of the code (most likely from a different class entirely).

Well, one easy way to track back through the code (presuming you don’t just want to open the debugger) is to put a:
new Throwable().printStackTrace();

…somewhere in it. Don’t throw the exception, just use it to dump the stack trace. Then you can trace back up to figure out what code might be swallowing the exception.

But, if you are using nifty and this is invoked from nifty… then that’s what’s swallowing the exception. Way back when, I used to put try/catch blocks around the insides of every one of nifty callback methods just to be sure I wasn’t losing exceptions.

Workaround,

start in debug mode, and add a breakpoint at the generic exceptions constructors.

Probably the generation code is running in an Executor that eats the exception. If this is the TerrainGrid I think sploreg fixed that issue years ago, maybe it is back.