I'm trying to programme flood fill but the is any problem with recursion. Error msg says: "Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError"
Here is my code:
public class FillerSeedFill<PixelType> {
public RasterImage<PixelType> filler (RasterImage<PixelType> img,
int x, int y,
PixelType newPixel,
PixelType borderPixel,
PixelType currentPixel
){
RasterImage<PixelType> result = img;
if ( borderPixel != currentPixel){
if(currentPixel!=newPixel) {
result = result.withPixel(x, y, newPixel);
filler(img,x+1,y,newPixel,borderPixel,currentPixel);
filler(img,x-1,y,newPixel,borderPixel,currentPixel);
filler(img,x,y+1,newPixel,borderPixel,currentPixel);
filler(img,x,y-1,newPixel,borderPixel,currentPixel);
return result;
}
}
return result;
}
}
and in canvas:
if(jComboBoxSelectColoring.getSelectedIndex()==0){
System.out.println("Seed fill");
int currentPixel = 0x2f2f2f;
System.out.println(currentPixel);
fillerSeedFill.filler(rasterImage,
previousX,previousY,
0xC4D4AF,
0x8AC249,
currentPixel);
System.out.println(previousX+" "+previousY);
panel.repaint();
}
Is there any posible to change XSS in IDEA? I've remembered in Eclipse was something like it.(-XSS100M)
currentPixel is collor of canva's background (0x2f2f2f).
EDIT: In previousX and Y is int position of cursor from listener.
EDIT SOLVED: The problem was thar current pixel did not took actual value of color. It has const. 0x2f2f2f so comparation was nosence. :).. thanks everybody