嘿伙计们,我目前正在研究我自己的自定义帧缓冲区并将原语绘制到其中。哪个工作正常。
然而,我的问题是将基元填充为屏幕上的纯色。比如本例中的一个圆圈。
问题是我试图填补它,我得到一个堆栈溢出错误(这意味着递归函数永远不会结束)。
这是我用来填充该区域的递归函数...
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);
}
}
请注意,代码的北部和南部部分工作得非常好,并且仅当代码的东部和西部部分一起工作时才会发生错误(但如果我从函数中删除一个或另一个,它们自己工作得很好)。如果有人看到问题,您能否向我解释为什么东西方可能会相互影响?
非常感谢!