Iphone 洪水填充方法崩溃,访问错误,有什么想法吗?

Iphone 洪水填充方法崩溃,访问错误,有什么想法吗?,iphone,objective-c,ios,xcode,ipad,Iphone,Objective C,Ios,Xcode,Ipad,我的洪水填充方法由于错误的访问错误而崩溃,我找不到错误。有什么想法吗 当我启动我的应用程序时,我可以很好地绘制小对象,但当我想使用像油漆桶一样的泛洪填充来用油漆填充较大的对象时,它只会因严重的访问错误而崩溃 我是个傻瓜,我尝试了很多方法,递归的次数增加了,但仍然失败。 我在这个应用程序中使用ARC -(void)paintingBucket:(int)point point2:(int)point2 width:(int)width colorAtPoint:(UIColor *)color {

我的洪水填充方法由于错误的访问错误而崩溃,我找不到错误。有什么想法吗

当我启动我的应用程序时,我可以很好地绘制小对象,但当我想使用像油漆桶一样的泛洪填充来用油漆填充较大的对象时,它只会因严重的访问错误而崩溃

我是个傻瓜,我尝试了很多方法,递归的次数增加了,但仍然失败。 我在这个应用程序中使用ARC

-(void)paintingBucket:(int)point point2:(int)point2 width:(int)width colorAtPoint:(UIColor *)color {

int offset = 0;
int x = point;
int y = point2;
if (point<1025 && point2<705) {

offset = 4*((width*round(y))+round(x));

int alpha = data[offset];
int red = data[offset + 1];
int green = data[offset + 2];
int blue = data[offset + 3];
color1 = [UIColor colorWithRed:(green/255.0f) green:(red/255.0f) blue:(alpha/255.0f) alpha:(blue/255.0f)];

   if ([color1 isEqual: color] ) {

        color3 = self.currentColor ;
        CGFloat r,g,b,a;
        [color3 getRed:&r green:&g blue: &b alpha: &a];
        int reda = (int)(255.0 * r);
        int greena = (int)(255.0 * g);
        int bluea = (int)(255.0 * b);
        int alphaa = (int)(255.0 * a);
       // NSLog(@" red: %u green: %u blue: %u alpha: %u", reda, greena, bluea, alphaa);

        data[offset + 3] = alphaa;
        data[offset + 2] = reda;
        data[offset + 1] = greena;
        data[offset] = bluea;

        [self paintingBucket:x+1 point2:y  width:width colorAtPoint:color];
        [self paintingBucket:x point2:y+1  width:width colorAtPoint:color];
        [self paintingBucket:x-1 point2:y  width:width colorAtPoint:color];
        [self paintingBucket:x point2:y-1  width:width colorAtPoint:color];

            }

        }

    }
-(void)paintingBucket:(int)point2:(int)point2 width:(int)width colorAtPoint:(UIColor*)color{
整数偏移=0;
int x=点;
int y=点2;

如果(点,几乎可以肯定是堆栈溢出。当递归地用洪水填充某个区域时,堆栈上的项目数等于前端的长度,对于较大的区域,该长度可能相当长

您应该将递归方法替换为基于队列的方法来解决此问题。

您有

int x = point;
int y = point2;

if (point<1025 && point2<705) 
{
...

这可能是溢出的原因,因为递归不会因负值而停止。

也许您应该在控制台中查找任何崩溃信息,并找出调试器堆栈显示问题发生的位置。然后将该信息包含在帖子中。您正在写入数据[]数组。可能太小了。我不这么认为,因为数据数组代表位图像素,并且像素比我达到的迭代次数多得多。你得到的错误原因信息比你发布的要多。你需要学习如何查找和解释它。你能给我一个如何做的示例吗?或者一个与一些poi的链接问题的解决方案是什么?@lost4ever-Sure-看看,它们有易于遵循的队列伪代码或显式基于堆栈的方法。我尝试实现了这一点,但没有成功,并尝试了其他一些事情,但仍然失败,您能帮我一些示例代码吗?尝试添加“…&(x>0&&y>0)”我根本没帮上忙。不过还是谢谢你的建议。
    [self paintingBucket:x-1 point2:y  width:width colorAtPoint:color];
    [self paintingBucket:x point2:y-1  width:width colorAtPoint:color];