opiumhautopium1 Posted March 19, 2012 Share Posted March 19, 2012 Hi i have a Problem i write a well working skript but after a while i get the message stack overflow now i cant find where i make something wrong i hope you can show me whats wrong with my code thx in advance.............. drive me crasy for 2 days Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted March 19, 2012 Share Posted March 19, 2012 (edited) 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 March 19, 2012 by shadowrecon Quote Link to comment Share on other sites More sharing options...
FHannes Posted March 19, 2012 Share Posted March 19, 2012 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. Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 19, 2012 Author Share Posted March 19, 2012 (edited) 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 March 19, 2012 by opiumhautopium1 Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted March 19, 2012 Share Posted March 19, 2012 (edited) lol i wrote a lot of text to explain that i havent a loop call itselfwhile 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 March 19, 2012 by shadowrecon Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 20, 2012 Author Share Posted March 20, 2012 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 Quote Link to comment Share on other sites More sharing options...
FHannes Posted March 20, 2012 Share Posted March 20, 2012 If you have an out of memory error, make sure you load every bitmap only once. Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 20, 2012 Author Share Posted March 20, 2012 (edited) 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 March 20, 2012 by opiumhautopium1 Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted March 20, 2012 Share Posted March 20, 2012 (edited) 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 March 20, 2012 by shadowrecon Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 21, 2012 Author Share Posted March 21, 2012 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) Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted March 21, 2012 Share Posted March 21, 2012 (edited) 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 March 21, 2012 by shadowrecon Quote Link to comment Share on other sites More sharing options...
FHannes Posted March 21, 2012 Share Posted March 21, 2012 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. Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 21, 2012 Author Share Posted March 21, 2012 (edited) 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 ?..........???????? Edited March 21, 2012 by opiumhautopium1 Quote Link to comment Share on other sites More sharing options...
FHannes Posted March 21, 2012 Share Posted March 21, 2012 As I've said twice before, load them only once. Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted March 21, 2012 Share Posted March 21, 2012 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. Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted March 21, 2012 Share Posted March 21, 2012 (edited) 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 March 21, 2012 by TroisVerites Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) i am very interesting to test the ways here .... tonight crashes the programm antistealth ... but i know now the loop redmm is not the memory overflow reason because scarscript runs 5 hours in this while loop ^^ Edited March 22, 2012 by opiumhautopium1 Quote Link to comment Share on other sites More sharing options...
TroisVerites Posted March 22, 2012 Share Posted March 22, 2012 (edited) Perhaps you can update the script file with the changes you made. And perhaps we can help you better. But follow the Freddy advices : "load them only once" , you don't free them. Edited March 22, 2012 by TroisVerites Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted March 24, 2012 Author Share Posted March 24, 2012 at the moment i test sucsessfull the first option without error ... i will give more information when i test the second one because i am interestet to test TroisVerites way^^ Quote Link to comment Share on other sites More sharing options...
opiumhautopium1 Posted April 7, 2012 Author Share Posted April 7, 2012 so i know already it was not a problem with my code all ways work right now it was a bug in scar but thanks i learn how to to the same thing on different and smarter ways so i want to say thank you to freddy shaddowrecon and troisverites Quote Link to comment Share on other sites More sharing options...