【发布时间】:2013-08-08 12:32:44
【问题描述】:
大家好,我目前正在开发我自己的自定义帧缓冲区并将原语绘制到其中。哪个工作正常。
然而,我的问题是将基元填充为屏幕上的纯色。比如本例中的圆圈。
问题是我试图填补它,我得到一个堆栈溢出错误(这意味着递归函数永远不会结束)。
这是我用来填充区域的递归函数...
private void filler(int position, byte r, byte g, byte b)
{
buffer[position] = r;
buffer[position + 1] = g;
buffer[position + 2] = b;
int northPosition = position - rowLength;
int southPosition = position + rowLength;
int westPosition = position - 3;
int eastPosition = position + 3;
//fills squares west of the current
/**/
System.out.println(position);
//fills squares to the east of the current
if(buffer[eastPosition] != r && buffer[eastPosition + 1] != g && buffer[eastPosition + 2] != b)
{
System.out.println("runs");
filler(eastPosition, r, g, b);
}
System.out.println(position);
//fills squares north of the current
if(buffer[northPosition] != r && buffer[northPosition + 1] != g && buffer[northPosition + 2] != b)
{
filler(northPosition,r,g,b);
}
//fills squares south of current
if(buffer[southPosition] != r && buffer[southPosition + 1] != g && buffer[southPosition + 2] != b)
{
filler(southPosition,r,g,b);
}
//fills squares west of current
if(buffer[westPosition] != r && buffer[westPosition + 1] != g && buffer[westPosition + 2] != b)
{
filler(westPosition, r, g, b);
}
}
请注意,代码的北部和南部部分工作得很好,只有当代码的东部和西部部分一起工作时才会出现错误(但如果我从函数中删除一个或另一个,它们自己工作得很好)。如果有人看到问题,您能否向我解释为什么东西方可能会相互影响?
非常感谢!
【问题讨论】:
-
filler()的示例输入是什么? -
因为它以字节为单位,它描绘了一个特定的位置。可能是 23345,200,0,0
-
你是东/西没有南/北吗?
-
很有趣,现在刚刚尝试过,它似乎在东方和西方都很好。删除了南北代码。
标签: java stack-overflow