Jump to content
opiumhautopium1

STACK Overflow

Recommended Posts

One thing i can see from the start is you have to many Global Vars! You should keep globals down to a minimum. The stack is the amount of memory you program has reserved for vars to store information(Call Stack is the technical name). If you have that many vars active constantly you constantly have all the memory reserved where as if you had local vars you script would reserve that space when they need to be used. One other problem could be using a shortint and really you needed a longint, and the space you reserved for the shortint is not enough to store the information, and should be a longint, but i dont see any of those in you script.

 

Here is a defination from the web:

In software, a stack overflow occurs when too much memory is used on the call stack. The call stack contains a limited amount of memory, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to overflow, typically resulting in a program crash.[1] This class of software bug is usually caused by one of two types of programming errors.[2] [/Quote]
Edited by shadowrecon
Link to comment
Share on other sites

One thing i can see from the start is you have to many Global Vars! You should keep globals down to a minimum. The stack is the amount of memory you program has reserved for vars to store information(Call Stack is the technical name). If you have that many vars active constantly you constantly have all the memory reserved where as if you had local vars you script would reserve that space when they need to be used. One other problem could be using a shortint and really you needed a longint, and the space you reserved for the shortint is not enough to store the information, and should be a longint, but i dont see any of those in you script.

 

I agree there shouldn't be this many global variables, however, the call stack is very large compared to the memory required to store all of those variables, I doubt that is the issue.

 

@opiumhautopium1: Is there any function in the script that calls itself? A stack overflow is most commonly caused by a function which recurses too often. Every time the function calls itself, the parameters for the previous call are dumped onto the stack, to be restored once you exit the deeper call to the function. If you keep recursing indefinitely, the stack will overflow as the space is limited.

 

EDIT: Note that when I say call itself, this can also happen indirectly... E.g.: Function1 calls Function2 which in turn calls Function1 again.

Link to comment
Share on other sites

lol i wrote a lot of text to explain that i havent a loop call itself

while i wrote here i saw a peace of code

If result= true then
         begin
           Result:=true;
           y:=y+3;
.....
.....

i forgot to delete Result:=true;......... ?could this be the reason for stack overflow?

i will test the script tonight

when I was so blind not to see the that, I'll kick myself in my ass^^

Edited by opiumhautopium1
Link to comment
Share on other sites

lol i wrote a lot of text to explain that i havent a loop call itself

while i wrote here i saw a peace of code

If result= true then
         begin
           Result:=true;
           y:=y+3;
.....
.....

i forgot to delete Result:=true;......... ?could this be the reason for stack overflow?

i will test the script tonight

when I was so blind not to see the that, I'll kick myself in my ass^^

 

I dont think that would cause it, but that is deff a performance issue. I also noticed you have a function that checks like 10 bitmaps in a row and each one makes the result true but doesnt exit after a result is true. maybe that could be the issue?

 

[scar]

Function Shoot_Npc: Boolean;

var x,y :Integer;

begin

writeln('kontrollpunkt Tentacle');

Result:=false;

if FindBitmapTolerance(WilddreizehnWhite, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(WilddreizehnBlue, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(TortugaGangWhite, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(TortugaGangBlue, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(LosRenegardosWhite, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(LosRenegardosBlue, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(TentacleWhite, x, y, Tolerance) then Result:=true;

if FindBitmapTolerance(TentacleBlue, x, y, Tolerance) then Result:=true;

If result= true then

begin

Result:=true;

y:=y+3;

writeln('kontrollpunkt Schiff GEFUNDEN und los gehts ');

mouse(x,y); mouse(x,y);

end;

end;

[/scar]

 

This is how i would solve that problem ( Also You had 2 mouse procedures look at the code above to see

[scar]

Function Shoot_Npc: Boolean;

var x,y,I :Integer;

begin

writeln('kontrollpunkt Tentacle');

For I := 0 to 7 do

Begin

Case I of

0: if FindBitmapTolerance(WilddreizehnWhite, x, y, Tolerance) then Result := true;

1: if FindBitmapTolerance(WilddreizehnBlue, x, y, Tolerance) then Result := true;

2: if FindBitmapTolerance(TortugaGangWhite, x, y, Tolerance) then Result := true;

3: if FindBitmapTolerance(TortugaGangBlue, x, y, Tolerance) then Result := true;

4: if FindBitmapTolerance(LosRenegardosWhite, x, y, Tolerance) then Result := true;

5: if FindBitmapTolerance(LosRenegardosBlue, x, y, Tolerance) then Result := true;

6: if FindBitmapTolerance(TentacleWhite, x, y, Tolerance) then Result := true;

7: if FindBitmapTolerance(TentacleBlue, x, y, Tolerance) then Result := true;

end;

If Result then

Break;

end;

If result then

begin

y:=y+3;

writeln('kontrollpunkt Schiff GEFUNDEN und los gehts ');

mouse(x,y);

end;

end;

[/scar]

 

This would stop searching for bitmaps after it finds one of the bitmaps you were looking for. which would greatly increase performance of the bot.

Edited by shadowrecon
Link to comment
Share on other sites

thx for answere i try last night

 if  FindBitmapTolerance(WilddreizehnWhite, x, y, Tolerance)  then Result:=true else;
     if  FindBitmapTolerance(WilddreizehnBlue, x, y, Tolerance)   then Result:=true else;

if then else

but i become a memory error after a coupple of hours (not stack overflow) run out of memory....... so i try your code next time :-) and the mouse, mouse is right because i need 2 klicks ( mark and execute )

thx a lot

Link to comment
Share on other sites

If you have an out of memory error, make sure you load every bitmap only once.

hmm the mainloop itself are only 2 funktions i look that funtion 2 returns to the main loop

begin
 player_rot:=255;
 Seamap;
 writeln('KontrollpunktREDMM');
 if (FindColorTolerance(x,y,player_rot, mmx1, mmy1, mmx2, mmy2,20)=true)then
        begin
        sendkeys('G');
         Elite_munition;
         result:=true;
           while (FindColorTolerance(x,y,player_rot, mmx1, mmy1, mmx2, mmy2,20)=true) do
             begin
               writeln('roter punkt ich wart bis er weg ist') ;
               wait(100);
             end;
         end;
 Hohl_Munition;
 result:=false;
  AntistealthWindow;
end;


Function Shoot_Npc: Boolean;
var x,y :Integer;
begin
         writeln('kontrollpunkt Tentacle');
         Result:=false;
     if  FindBitmapTolerance(WilddreizehnWhite, x, y, Tolerance)  then Result:=true else;
     if  FindBitmapTolerance(WilddreizehnBlue, x, y, Tolerance)   then Result:=true else;
     if  FindBitmapTolerance(SinclairsMenWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(SinclairsMenBlue, x, y, Tolerance)   then  Result:=true else;
     if  FindBitmapTolerance(TortugaGangWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(TortugaGangBlue, x, y, Tolerance)   then  Result:=true else;
     if  FindBitmapTolerance(RatPackWhite, x, y, Tolerance)  then Result:=true else;
     if  FindBitmapTolerance(RatPackBlue, x, y, Tolerance)   then Result:=true else;
     if  FindBitmapTolerance(LosRenegardosWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(LosRenegardosBlue, x, y, Tolerance)   then  Result:=true else;
     if  FindBitmapTolerance(TentacleWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(TentacleBlue, x, y, Tolerance)   then  Result:=true else;
       writeln('nix gefunden');
     If result= true then
         begin
           Result:=true;
           y:=y+3;
           writeln('kontrollpunkt Schiff GEFUNDEN und los gehts ');
           mouse(x,y); mouse(x,y);
         end;
end;

the funktions elitemunition and holmunition only press a key with the global String vars

Hohlmunition:='3';

Elitemunition:='1';

Procedure Elite_Munition;
var u: string;
begin
u:=Elitemunition
typekeys(u);
end;

Procedure Hohl_Munition;
var t: string;
begin
t:=Hohlmunition
typekeys(t);
end;

the last thing i use is ....too change between the 2 windows i need ( if no red pixels at the web page goto window antstealth)

procedure SeaMap;
begin
 writeln('kontrollpunkt Seamap');
 SetClientWindowHandle(SM);
 GetClientDimensions(Seamap_x2, Seamap_y2);
 ActivateClient;
 //Writeln('Seamap_y2: '+inttostr(Seamap_x2)+'x '+inttostr(Seamap_y2));
end;

procedure AntistealthWindow;
begin
 writeln('kontrollpunkt Antistealth');
 SetClientWindowHandle(PO);
 GetClientDimensions(Antistealth_x2, Antistealth_y2);
 ActivateClient;
 //Writeln('Antistealth_y2: '+inttostr(Antistealth_x2)+'x '+inttostr(Antistealth_y2));
end;

the rest is not in the mainloop

 repeat
writeln('REPEAT MAINLOOP');
wait(1200);
if RedMM = false then Shoot_Npc;
until false;

and called at the beginning to check if the right things are open... hope the idea from shadowrecon with case loop will fix it ?! ^^

Edited by opiumhautopium1
Link to comment
Share on other sites

hmm the mainloop itself are only 2 funktions i look that funtion 2 returns to the main loop

begin
 player_rot:=255;
 Seamap;
 writeln('KontrollpunktREDMM');
 if (FindColorTolerance(x,y,player_rot, mmx1, mmy1, mmx2, mmy2,20)=true)then
        begin
        sendkeys('G');
         Elite_munition;
         result:=true;
           while (FindColorTolerance(x,y,player_rot, mmx1, mmy1, mmx2, mmy2,20)=true) do
             begin
               writeln('roter punkt ich wart bis er weg ist') ;
               wait(100);
             end;
         end;
 Hohl_Munition;
 result:=false;
  AntistealthWindow;
end;


Function Shoot_Npc: Boolean;
var x,y :Integer;
begin
         writeln('kontrollpunkt Tentacle');
         Result:=false;
     if  FindBitmapTolerance(WilddreizehnWhite, x, y, Tolerance)  then Result:=true else;
     if  FindBitmapTolerance(WilddreizehnBlue, x, y, Tolerance)   then Result:=true else;
     if  FindBitmapTolerance(SinclairsMenWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(SinclairsMenBlue, x, y, Tolerance)   then  Result:=true else;
     if  FindBitmapTolerance(TortugaGangWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(TortugaGangBlue, x, y, Tolerance)   then  Result:=true else;
     if  FindBitmapTolerance(RatPackWhite, x, y, Tolerance)  then Result:=true else;
     if  FindBitmapTolerance(RatPackBlue, x, y, Tolerance)   then Result:=true else;
     if  FindBitmapTolerance(LosRenegardosWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(LosRenegardosBlue, x, y, Tolerance)   then  Result:=true else;
     if  FindBitmapTolerance(TentacleWhite, x, y, Tolerance)  then  Result:=true else;
     if  FindBitmapTolerance(TentacleBlue, x, y, Tolerance)   then  Result:=true else;
       writeln('nix gefunden');
     If result= true then
         begin
           Result:=true;
           y:=y+3;
           writeln('kontrollpunkt Schiff GEFUNDEN und los gehts ');
           mouse(x,y); mouse(x,y);
         end;
end;

the funktions elitemunition and holmunition only press a key with the global String vars

Hohlmunition:='3';

Elitemunition:='1';

Procedure Elite_Munition;
var u: string;
begin
u:=Elitemunition
typekeys(u);
end;

Procedure Hohl_Munition;
var t: string;
begin
t:=Hohlmunition
typekeys(t);
end;

the last thing i use is ....too change between the 2 windows i need ( if no red pixels at the web page goto window antstealth)

procedure SeaMap;
begin
 writeln('kontrollpunkt Seamap');
 SetClientWindowHandle(SM);
 GetClientDimensions(Seamap_x2, Seamap_y2);
 ActivateClient;
 //Writeln('Seamap_y2: '+inttostr(Seamap_x2)+'x '+inttostr(Seamap_y2));
end;

procedure AntistealthWindow;
begin
 writeln('kontrollpunkt Antistealth');
 SetClientWindowHandle(PO);
 GetClientDimensions(Antistealth_x2, Antistealth_y2);
 ActivateClient;
 //Writeln('Antistealth_y2: '+inttostr(Antistealth_x2)+'x '+inttostr(Antistealth_y2));
end;

the rest is not in the mainloop

 repeat
writeln('REPEAT MAINLOOP');
wait(1200);
if RedMM = false then Shoot_Npc;
until false;

and called at the beginning to check if the right things are open... hope the idea from shadowrecon with case loop will fix it ?! ^^

 

Id just go through and try to optimize your code to speak and eliminate anything you have that is being repetitive, but does not need to be. Heres a more efficient setup id use instead of if statements its prob 10 ms faster but still 10 ms.. lol.

[scar]

Function Shoot_Npc: Boolean;

var x,y,I :Integer;

begin

writeln('kontrollpunkt Tentacle');

For I := 0 to 7 do // loops through all 7 cases

Begin

Case I of

0: Result := FindBitmapTolerance(WilddreizehnWhite, x, y, Tolerance);

1: Result := FindBitmapTolerance(WilddreizehnBlue, x, y, Tolerance);

2: Result := FindBitmapTolerance(TortugaGangWhite, x, y, Tolerance);

3: Result := FindBitmapTolerance(TortugaGangBlue, x, y, Tolerance);

4: Result := FindBitmapTolerance(LosRenegardosWhite, x, y, Tolerance);

5: Result := FindBitmapTolerance(LosRenegardosBlue, x, y, Tolerance);

6: Result := FindBitmapTolerance(TentacleWhite, x, y, Tolerance);

7: Result := FindBitmapTolerance(TentacleBlue, x, y, Tolerance);

end;

If Result then // breaks loop when one of the results is true

Break;

end;

If result then // if result = true then..

begin

y:=y+3;

writeln('kontrollpunkt Schiff GEFUNDEN und los gehts ');

mouse(x,y);

end;

end;

[/scar]

 

also why dont you free the bitmaps after you done using them then reload them then you need to use them. I dont know how quickly your using them but maybe scar is loosing focus/the pointers of the bitmaps after a while of running.

Edited by shadowrecon
Link to comment
Share on other sites

lol there is a simple reason i thoght it is better to load the bitmaps only one time ........ as again and again and again ... ....... the funktion run one time a second.......

........ is it better to reload the bmp every time ? (later it will be up to 30 bmp s at one time)

 

I personally like to load them when i use them then unload them at the the end of the functions that i use them in. Id give it a shot trying to load them at the start of the function and freeing them at the end of the function. see if that solves your problem.

 

Also if there are BMP's that are not used dont load them all at once separate the load out so you can load only the needed BMP's.

Edited by shadowrecon
Link to comment
Share on other sites

lol there is a simple reason i thoght it is better to load the bitmaps only one time ........ as again and again and again ... ....... the funktion run one time a second.......

........ is it better to reload the bmp every time ? (later it will be up to 30 bmp s at one time)

 

You must load the bitmaps only 1 time, if you load them over and over again, the memory will get flooded if you do not free them.

Link to comment
Share on other sites

but what is better load and free them all times 60 times a minute all 30 bmp ....... or load them one times till i stopp script ?..........????????

 

oh if ur using them that often load them once as Freddy stated =p

 

Do the bit maps change color? Are they on the mini map or one the screen? If they do not change color and there on the mini-map try using a count color method and that could speed up you detection system of what ever your trying to detect.

Link to comment
Share on other sites

Perhaps a better way to code this function:

 

[sCAR]

Function Shoot_Npc: Boolean;

var

x,y,i :Integer;

ArrayBmp: array of integer;

begin

writeln('kontrollpunkt Tentacle');

Result:=false;

// Perhaps You can make a function to get this array.

ArrayBmp := [ WilddreizehnWhite,WilddreizehnBlue,

TortugaGangWhite,TortugaGangBlue,

LosRenegardosWhite,LosRenegardosBlue,

TentacleWhite,TentacleBlue];

 

for i:=Low( ArrayBmp) to High(ArrayBmp) do

begin

Result := FindBitmapTolerance(ArrayBmp, x, y, Tolerance);

if ( Result ) then break;

end;

 

If Result= true then

begin

y:=y+3;

writeln('kontrollpunkt Schiff GEFUNDEN und los gehts ');

mouse(x,y);

end;

end;

[/sCAR]

Edited by TroisVerites
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...