【发布时间】:2014-08-25 18:29:09
【问题描述】:
如果我用参数 0,0,0,15 输入它,我会得到一个堆栈溢出异常。这可能是什么原因?是无限递归还是堆栈实际上太多了?光照3D阵列大小为16 * 16 * 128
private void updateLight(int x, int y, int z, byte lightValue) {
if (lightValue == 1 || lighting[x][z][y] != -1 || voxels[x][z][y] != 0) {
return;
}
lighting[x][z][y] = lightValue;
if (x - 1 >= 0) {
updateLight(x - 1, y, z, --lightValue);
}
if (x + 1 < lighting.length) {
updateLight(x + 1, y, z, --lightValue);
}
if (z - 1 >= 0) {
updateLight(x, y, z - 1, --lightValue);
}
if (z + 1 < lighting[0].length) {
updateLight(x, y, z + 1, --lightValue);
}
if (y - 1 >= 0) {
updateLight(x, y - 1, z, --lightValue);
}
if (y + 1 < lighting[0][0].length) {
updateLight(x, y + 1, z, --lightValue);
}
}
【问题讨论】:
-
不是循环,而是递归
-
@Alex 哎呀这就是我的意思。
-
要获得stackoverflow,它不应该是无限的,只是比你堆栈拥有的更多。
-
@Alex 我知道。但我有点怀疑,当大多数操作立即被过滤时,堆栈是否会溢出 16 * 16 * 128 操作。这就是为什么我要问这里是否存在无限递归。
-
你可以在调试器中签入
标签: stack-overflow infinite-loop