PDA

View Full Version : Stack Overflow error...



BenLand100
04-04-2006, 09:03 PM
This is not a problem I have with scar inparticular but it is in a plugin I'm working on (written in delphi ;)). Anyway the problem is I have to get a function to call itself untill it gets to the end of the line its following. It starts at one end and follows it pixel by pixel to the end. Now, after X number of calls (unknown as of now ;)) I get a Stack Overflow error meaning a method is stuck in an endless loop... is there anyway to turn that error off? As in with a compiler directive or such? I am almost 100% shure it will not ever go into an endless loop however much it looks like it will ;) I don't want to give the whole source yet but this is the function...

function follow(x, y, max: integer): boolean;
var
xR, Xl, yU, yD, curIndex, tempX, tempY, tempIndex: integer;
flag: boolean;
begin
xR:= x + 1;
xL:= x - 1;
yU:= y + 1;
yD:= y - 1;
curIndex:= x + y * width;
if (yU >= height) then
yU:= height - 1;
if (yD < 0) then
yD:= 0;
if (xR >= width) then
xR:= width - 1;
if (xL < 0) then
xL:= 0;
if (data[curIndex] = 0) then
begin
data[curIndex]:= magnitude[curIndex];
flag:= false;
tempX:= xL;
repeat
if (tempX > xR) then
break;
tempY:= yD;
repeat
if (tempY > yU) then
break;
tempIndex:= tempX + tempY * width;
if (((tempY <> y) or (tempX <> x)) and (magnitude[tempIndex] >= max) and (follow(tempX, tempY, max))) then
begin
flag:= true;
break;
end;
tempY:= tempY + 1;
until (false);
if (not flag) then
break;
tempX:= tempX + 1;
until (false);
result:= true;
end else begin
result:= false;
end;
end;