SRL Archive - OSR Help

Memory usage goes up rapidly mad


CephaXz

2012-08-24 09:29:09

Function PickItem: Boolean;
var
a: Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
begin
repeat
FixDatSixHours;
FindNormalRandoms;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.58,0.87);

FindColorsTolerance(TPA, 5533524, MSX1, MSY1, MSX2, MSY2, 8);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 20, 15);
//SortATPAFromSize(ATPA, 300, true);

if Length(ATPA) < 1 then
begin
writeln('blabla');
end else
begin
MP := MiddleTPA(ATPA[0]);
MMouse(MP.x, MP.y, 1, 1);
if WaitUptext('ake', 500) then
ClickMouse2(mouse_Left);
end;
wait(RandomRange(300, 600));
until InvFull;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

When my script reach this part, it will keep picking up items until inventory is full. But during this time, the memory usage keep going up, always end up having an error while my Simba memory usage is over 1.5gb.

Is it because of the repeating of color finding function that cause this? Or is it because of other causes. And if so, how can I resolve this problem?

cycrosism

2012-08-24 09:31:54

I would suggest splitting it into 2 functions, one to find the TPA and the other to click it. That was how I made my scripts. Try that and see if it solves this problem

CephaXz

2012-08-24 09:33:20

From: cycrosism
I would suggest splitting it into 2 functions, one to find the TPA and the other to click it. That was how I made my scripts. Try that and see if it solves this problem


Can you explain how does that resolve the memory usage problem?

masterBB

2012-08-24 09:33:36

Use wrappers, functions that return TPA and ATPA types will hog memory.

TPAtoATPAExWrap(ATPA, TPA, 20, 15);

We don't got a wrapper yet for middle tpa, you might want to push a fix for that.

cycrosism

2012-08-24 09:35:29

From: CephaXz
Can you explain how does that resolve the memory usage problem?


I had my functions setup like that and I never had any memory issues. Hence why I said "Try that and see if it solves this problem".

CephaXz

2012-08-24 09:36:15

From: masterBB
Use wrappers, functions that return TPA and ATPA types will hog memory.


You mind giving an example based on the function above? TPA and ATPA is the best object finding I've learnt :p

EDIT: I see, so as long as the function has a 'wrap' in its name, it won't hog memory?


From: cycrosism
I had my functions setup like that and I never had any memory issues. Hence why I said "Try that and see if it solves this problem".


I'll try it and see how it goes. By splitting do you mean something like this?


Function FindItem(x, y): Boolean;
begin
if found then
Result := True;
end;

Procedure TakeItem;
begin
if FindItem(x,y) then
mouse(x, y, left);
end;

CephaXz

2012-08-24 10:08:59

The wrapper function works amazingly! Thanks for all the help!

masterBB

2012-08-24 10:37:37

All the functions returning an array will hog the memory. This is because of a bug in pascalscript. We can't fix it, it is just another reason to wait for lape.

Flight

2012-08-24 12:28:31

I agree with masterBB; wrappers will help substantially here. I had the same problem before with an early version of LividFarmer; something to do with constantly searching for a color, getting a TPA, and then slipping that into a 2DTPA. Let me modify your function a bit and we'll see if it's any better for you.


Function PickItem: Boolean;
var
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
begin
Result := False; //Let's start off by making this function, by default, False

tmpCTS := GetColorToleranceSpeed; //Set all of these just one time...
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.58,0.87);

repeat
FixDatSixHours;
FindNormalRandoms;

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 5533524, MSX1, MSY1, MSX2, MSY2, 8); //Let's use spiral instead
TPAtoATPAExWrap(TPA, 20, 15, ATPA);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY)); //Sort this ATPA from our middle screen

if (Length(ATPA) > 0) then //Only proceed if...
begin
MP := MiddleTPA(ATPA[0]);
MMouse(MP.x, MP.y, 1, 1);
if WaitUptext('ake', 500) then
ClickMouse2(mouse_Left);
end;
wait(RandomRange(300, 600));
until(InvFull);

Result := InvFull;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

Let me know if that helps any.

CephaXz

2012-08-24 14:24:49

From: masterBB
All the functions returning an array will hog the memory. This is because of a bug in pascalscript. We can't fix it, it is just another reason to wait for lape.


I see. That explains everything I need to know for now. Thanks!


From: Flight
I agree with masterBB; wrappers will help substantially here. I had the same problem before with an early version of LividFarmer; something to do with constantly searching for a color, getting a TPA, and then slipping that into a 2DTPA. Let me modify your function a bit and we'll see if it's any better for you.


Function PickItem: Boolean;
var
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
begin
Result := False; //Let's start off by making this function, by default, False

tmpCTS := GetColorToleranceSpeed; //Set all of these just one time...
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.58,0.87);

repeat
FixDatSixHours;
FindNormalRandoms;

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 5533524, MSX1, MSY1, MSX2, MSY2, 8); //Let's use spiral instead
TPAtoATPAExWrap(TPA, 20, 15, ATPA);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY)); //Sort this ATPA from our middle screen

if (Length(ATPA) > 0) then //Only proceed if...
begin
MP := MiddleTPA(ATPA[0]);
MMouse(MP.x, MP.y, 1, 1);
if WaitUptext('ake', 500) then
ClickMouse2(mouse_Left);
end;
wait(RandomRange(300, 600));
until(InvFull);

Result := InvFull;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

Let me know if that helps any.


Thanks Flight, that helps a lot! Currently the function is very different from the one in first post this thread. I'm still doing some testings with it, so you can see I have not used Results in it. But I have taken some parts from the one you edit into my script!

For the part where you only proceed if Length is more than 0, I always experience error out of range. The weird thing is it should just skip this step if Length is 0. So I made it to proceed when Length is less than 1 first, and do some failsafes. That solved my problem, but I don't know how lol.

mormonman

2012-08-24 16:20:39

From: masterBB
Use wrappers, functions that return TPA and ATPA types will hog memory.

TPAtoATPAExWrap(ATPA, TPA, 20, 15);

We don't got a wrapper yet for middle tpa, you might want to push a fix for that.


https://github.com/MerlijnWajer/Simba/pull/127/files