SRL Archive - OSR Help

(Simba)Bitmap leaking


Flight

2011-02-15 06:35:10

I made a quick 30-minute script just as a test for working more in-debt with bitmaps, and I've tried every route I can think of and I'm still ending up with hundreds of unfreed bitmaps per minute.
Note: This is not for Runescape, therefore I do not use reflection, ect…

Procedure in my script:
procedure Attack;
Var
x,y,x2,y2,
ChickenPic,
AttackText: integer;
begin
ChickenPic := BitmapFromString(10, 12, 'meJxjYIACAYFzQMSADUCk4AhNNq' +
'i6BYKwKgCKw9XgMgFNAZq9cAVoGtFkMd0MF4QYjksWqwJMLpp6TPd' +
'jehlZAQCzQzK8');
AttackText := BitmapFromString(23, 14, 'meJxjYKACaGBgOJ1CBUOWU+4UsD' +
'kEBbGqQVOw0wJdBIJWYOMiiyxHEplCokuWYxPHdC1+Q9DE4Q4jw5A' +
'GDJdMwVCAhzsFtzLk4MVvCK4waUA1B81tuLgNRMQ+PUEDNRAA7fAt' +
'5w==');
setbitmapname(ChickenPic,'ChickenPic');
setbitmapname(AttackText,'AttackText');
if (FindTarget) then
begin
if (FindBitmapToleranceIn(ChickenPic,x,y,5,5,450,320,25)) then
begin
FreeBitmap(ChickenPic);
x := x+Random(20);
y := y+Random(10);
MoveMouse(x,y);
wait(200+Random(100));
ClickMouse(x,y,mouse_Left);
wait(300+Random(100));
if (FindBitmapToleranceIn(AttackText,x2,y2,5,5,450,320,25)) then
begin
FreeBitmap(AttackText);
x2 := x2+Random(20);
y2 := y2+Random(10);
MoveMouse(x2,y2);
wait(200+Random(100));
ClickMouse(x2,y2,mouse_Left);
FindTarget := False;
end else
begin
FreeBitmap(AttackText);
end;
end else
begin
FreeBitmap(ChickenPic);
end;
end;
end;

And here is my main script loop:
begin
KillCount := 0;
FindTarget := True;
repeat
CheckLogin;
CheckBmps;
if(FindTarget) then
Attack;
until(false)
end.

Any suggestions or ideas would be grand, but I'm assuming it's a very simple mistake I'm making somewhere, probably obvious to you guys.

Gu3st...

2011-02-15 06:50:48

You're right about that it's a very simple mistake. As you have it at the moment, it will only free the bitmaps if it doesn't find the colors. If FindTarget returns false then it wont free any of them.

Take away all the FreeBitmap()s and add some new to the end of the function like so:
FreeBitmap(ChickenPic);
FreeBitmap(AttackText);
end;

Flight

2011-02-15 07:42:32

Yeah that pretty much took care of the problem, but I'm still curious as to why my original procedures didn't correctly free the bitmaps…

if (FindBitmapToleranceIn(ChickenPic,x,y,5,5,450,320,25)) then
begin
FreeBitmap(ChickenPic);
Assuming the bitmap was freed immediately after finding, should that not have correctly freed it?
 end else
begin
FreeBitmap(ChickenPic);
end;
^Saying even if it was not found, it should have been freed.

The only reason I can think of is if the bitmap is declared initially when the procedure is called?

But in any case, thanks a million, Zyt3x, believe me when I say that I very much appreciate it.

Gu3st...

2011-02-15 10:58:33

No problem :)

Here was the problem:
procedure Attack;
Var
x,y,x2,y2,
ChickenPic,
AttackText: integer;
begin
ChickenPic := BitmapFromString(10, 12, 'meJxjYIACAYFzQMSADUCk4AhNNq' +
'i6BYKwKgCKw9XgMgFNAZq9cAVoGtFkMd0MF4QYjksWqwJMLpp6TPd' +
'jehlZAQCzQzK8');
AttackText := BitmapFromString(23, 14, 'meJxjYKACaGBgOJ1CBUOWU+4UsD' +
'kEBbGqQVOw0wJdBIJWYOMiiyxHEplCokuWYxPHdC1+Q9DE4Q4jw5A' +
'GDJdMwVCAhzsFtzLk4MVvCK4waUA1B81tuLgNRMQ+PUEDNRAA7fAt' +
'5w==');
setbitmapname(ChickenPic,'ChickenPic');
setbitmapname(AttackText,'AttackText');
if (FindTarget) then
begin
//Code goes here.
end;
end;
If FindTarget returns false then no FreeBitmap() is ever called.

Wizzup?

2011-02-15 11:16:36

Perhaps we could make a function in SRL that loads, finds and frees a bitmap. Although you probably don't want to call that too often since you'd be doing a lot of extra loads/stores. ;)

Flight

2011-02-15 11:19:30

I'm not really sure where over usage of storing bitmaps would be a problem. I've run a script with even a big leak that ran up around 7,000 unfreed bitmaps over night for a straight 8-9 hours non stop, and it was still running strong without signs of slowing down in speed.

Wizzup?

2011-02-17 04:33:48

From: Flight
I'm not really sure where over usage of storing bitmaps would be a problem. I've run a script with even a big leak that ran up around 7,000 unfreed bitmaps over night for a straight 8-9 hours non stop, and it was still running strong without signs of slowing down in speed.


Well, where else do you load bitmaps? For the record, I meant this:


function LoadFindFreeBitmapToleranceIn(bmpstring: string; var x, y: integer; x1,y1,x2,y2,tolerance: integer): boolean;

Flight

2011-02-17 05:41:37

Is there an instance in where Simba will load/create bitmaps that the script doesn't define? I've been recently experimenting with a new script of mine, in this script I use a separate file (I call it as you would a normal Include file) to declare a few larger-sized bitmaps, each of which I have set a custom "name" to each, like I do all my bitmaps.

However, when I stop my script I'll have somewhere around 100 or so bitmaps unfreed per minute, and I've freed all my declared bitmaps correctly, but the odd thing is the unfreed bitmaps aren't named so they're not of my creation. Is it normal for Simba to 'produce' bitmaps? :s

Wizzup?

2011-02-17 05:43:01

From: Flight
Is there an instance in where Simba will load/create bitmaps that the script doesn't define? I've been recently experimenting with a new script of mine, in this script I use a separate file (I call it as you would a normal Include file) to declare a few larger-sized bitmaps, each of which I have set a custom "name" to each, like I do all my bitmaps.

However, when I stop my script I'll have somewhere around 100 or so bitmaps unfreed per minute, and I've freed all my declared bitmaps correctly, but the odd thing is the unfreed bitmaps aren't named so they're not of my creation. Is it normal for Simba to 'produce' bitmaps? :s


No; Simba doesn't create any managed bitmaps. Perhaps it's a function in SRL / MSI / Reflection? Care to show your code / script?

Flight

2011-02-17 05:56:53

Ok, this is the procedure inside the main script itself which loads the bitmaps in my include. (Also, don't laugh at the code, I know it's sloopy but understand this is beta stage)
procedure Walk;
Var x,y,x2,y2,
x3,y3,x4,y4,
x5,y5,x6,y6,
x7,y7,x8,y8,
x9,y9,x10,y10,
x11,y11:integer;
begin
LogsText := BitmapFromString(23, 10, 'meJxrYDBpYMAHGsBoqwUWQSSEz5AlSOxtZnATTJYimXY0CZ8haA5owCbeALYIvyFw21ENMVmCqoYMQxhgVgPR0WQEFxdADhO0sEWzDhNhKkANHBNkxZNwuwE/wGMpkQDTXw3UQADo6zdd');
setbitmapname(LogsText,'LogsText');
//~Produce walking coordinates~//
x := 200+Random(15);
y := 310+Random(10);
x2 := 265+Random(20);
y2 := 240+Random(15);
x3 := 5+Random(20);
y3 := 135+Random(20);
x4 := 5+Random(10);
y4 := 170+Random(20);
x5 := 290+Random(30);
y5 := 5+Random(10);
x6 := 340+Random(25);
y6 := 5+Random(10);
x7 := 340+Random(20);
y7 := 5+Random(10);
x8 := 355+Random(25);
y8 := 140+Random(10);
x10 := 360+Random(15);
y10 := 310+Random(10);
x11 := 360+Random(15);
y11 := 310+Random(10);
MoveMouse(x,y);
wait(350+Random(200));
ClickMouse(x,y,mouse_Left);
wait(2000+Random(400));
repeat
if ((GetRegion = 'R_OutsideMine') And (Clicked = False)) then
begin
Clicked := True;
MoveMouse(x2,y2);
wait(350+Random(200));
ClickMouse(x2,y2,mouse_Left);
wait(1800+Random(400));
MoveMouse(x3,y3);
wait(350+Random(200));
ClickMouse(x3,y3,mouse_Left);
wait(2000+Random(400));
WStage := 1;
end else if ((WStage = 1) And (GetRegion = 'R_FoxBuilding') And (Clicked = True)) then
begin
Clicked := False;
MoveMouse(x4,y4);
wait(350+Random(200));
ClickMouse(x4,y4,mouse_Left);
wait(2000+Random(400));
WStage := 2;
end else if ((WStage = 2) And (GetRegion = 'R_OutsideOakland') And (Clicked = False)) then
begin
Clicked := True;
MoveMouse(x5,y5);
wait(350+Random(200));
ClickMouse(x5,y5,mouse_Left);
wait(2000+Random(400));
WStage := 3;
end else if ((WStage = 3) And (GetRegion = 'R_Furnace') And (Clicked = True)) then
begin
Clicked := False;
MoveMouse(x6,y6);
wait(350+Random(200));
ClickMouse(x6,y6,mouse_Left);
wait(2000+Random(400));
WStage := 4;
end else if ((WStage = 4) And (GetRegion = 'R_FurnaceNorthA') And (Clicked = False)) then
begin
Clicked := True;
MoveMouse(x7,y7);
wait(350+Random(200));
ClickMouse(x7,y7,mouse_Left);
wait(2000+Random(400));
WStage := 5;
end else if ((WStage = 5) And (GetRegion = 'R_FurnaceNorthB') And (Clicked = True)) then
begin
Clicked := False
MoveMouse(x8,y8);
wait(350+Random(200));
ClickMouse(x8,y8,mouse_Left);
wait(350+Random(200));
if (FindBitmapToleranceIn(LogsText,x9,y9,340,5,425,190,25)) then
begin
Writeln('Taking logs');
x9 := x9+Random(20);
y9 := y9+Random(10);
MoveMouse(x9,y9);
wait(350+Random(200));
ClickMouse(x9,y9,mouse_Left);
wait(3100+Random(300));
MoveMouse(x10,y10);
wait(350+Random(200));
ClickMouse(x10,y10,mouse_Left);
wait(2000+Random(400));
//WStage := 6; //Skip it
WStage := 7;
end;
end else if ((WStage = 7) And (GetRegion = 'R_FurnaceNorthA') And (Clicked = False)) then
begin
Clicked := True;
MoveMouse(x11,y11);
wait(350+Random(200));
ClickMouse(x11,y11,mouse_Left);
wait(2000+Random(300));
WStage := 8;
end else
begin
Writeln('Lost!');
end;
until(WStage = 8)
FreeBitmap(LogsText);
PStage := 2;
end;
And this (below) is in the main script loop (also repeated)
if(PStage = 1) then
Walk;
And here is the "GetRegion" function in my include (Not including the bitmaps defined within the function, or should the be globally defined?):

function GetRegion: String;
Var
R_HeartMine,R_FoxBuilding,
R_Furnace,R_FurnaceNorthA,
R_FurnaceNorthB,R_InsideOakland,
R_OutsideMine,R_OutsideOakland,
x,y: integer;
begin
setbitmapname(R_HeartMine,'R_HeartMine');
setbitmapname(R_FoxBuilding,'R_FoxBuilding');
setbitmapname(R_Furnace,'R_Furnace');
setbitmapname(R_FurnaceNorthA,'R_FurnaceNorthA');
setbitmapname(R_FurnaceNorthB,'R_FurnaceNorthB');
setbitmapname(R_HeartMine,'R_OutsideOakland');
setbitmapname(R_HeartMine,'R_InsideOakland');
setbitmapname(R_HeartMine,'R_OutsideMine');

if (FindBitmapToleranceIn(R_HeartMine,x,y,0,0,455,325,25)) then
begin
Result := 'R_HeartMine';
end else if (FindBitmapToleranceIn(R_FoxBuilding,x,y,0,0,455,325,25)) then
begin
Result := 'R_FoxBuilding';
end else if (FindBitmapToleranceIn(R_Furnace,x,y,0,0,455,325,25)) then
begin
Result := 'R_Furnace';
end else if (FindBitmapToleranceIn(R_FurnaceNorthA,x,y,0,0,455,325,25)) then
begin
Result := 'R_FurniceNorthA';
end else if (FindBitmapToleranceIn(R_FurnaceNorthB,x,y,0,0,455,325,25)) then
begin
Result := 'R_FurnaceNorthB';
end else if (FindBitmapToleranceIn(R_OutsideMine,x,y,0,0,455,325,25)) then
begin
Result := 'R_OutsideMine';
end else if (FindBitmapToleranceIn(R_OutsideOakland,x,y,0,0,455,325,25)) then
begin
Result := 'R_OutsideOakland';
end;
FreeBitmap(R_HeartMine);
FreeBitmap(R_FoxBuilding);
FreeBitmap(R_Furnace);
FreeBitmap(R_FurnaceNorthA);
FreeBitmap(R_FurnaceNorthB);
FreeBitmap(R_OutsideMine);
FreeBitmap(R_OutsideOakland);
end;

I have the bitmaps declared within 'GetRegion' function, they're pretty big so I didn't include them above.

Wizzup?

2011-02-17 05:59:18

Can you mark where you load the bitmaps in GetRegion? Just with a comment or so. I suppose above the SetBitmapName… calls? Also, unrelated - if this is a script for runescape you should really use Mouse() instead of MoveMouse + ClickMouse.

Flight

2011-02-17 06:11:57

Yes directly above SetBitmapName and below 'begin' in the 'GetRegion' function.

No, definitely not Runescape. :P But I'll still keep that in mind.

Oh yeah, I do have silent mouse and silent keys working, but unfortunately I'm still unable to minimize the game, but that's on a different note and I'll experiment with that another time.

Wizzup?

2011-02-17 06:24:14

Well, I see 8 variables for bitmaps. Not all are assigned a name; you give the same bitmap several names too. And at the end you free 7 bitmaps, not 8? But then again, I don't know if you load 8 bitmaps.

Flight

2011-02-17 06:28:21

Ah yes I see this part now:
setbitmapname(R_HeartMine,'R_OutsideOakland');
setbitmapname(R_HeartMine,'R_InsideOakland');
setbitmapname(R_HeartMine,'R_OutsideMine');
MyIQ +5;

But still I have declared 8 bitmaps and named 8 bitmaps. Let me fix that error quick and see what comes up.

Edit:
Yes that took care of the ghost bitmaps I was getting, but still flooded unfreed bitmaps. I'll do a bit more playing around and see what I can come up with, but if you see something I missed please by all means share. :)

Wizzup?

2011-02-17 06:56:44

Well, what bitmaps aren't freed. Now that you have the names it should be easier to find out?

Flight

2011-02-17 07:23:05

Problem solved. You were right, the un-named bitmaps were because of naming the same bitmap with multiple names. (This was because I copied lines of text to save time, apparently I was rushing myself :P)

And in the GetRegion function I didn't have a check for "R_InsideOakland", which in turn made me skip over the freeing of the R_InsideOakland bitmap, so that's where my leak was. Thanks a million Wizzup!