Results 1 to 16 of 16

Thread: (Simba)Bitmap leaking

  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default (Simba)Bitmap leaking

    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:
    Simba Code:
    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:
    Simba Code:
    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.

  2. #2
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    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:
    Simba Code:
    FreeBitmap(ChickenPic);
      FreeBitmap(AttackText);
    end;

  3. #3
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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...

    Simba Code:
    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?
    Simba Code:
    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.

  4. #4
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    No problem

    Here was the problem:
    Simba Code:
    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.

  5. #5
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    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.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  6. #6
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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.
    Last edited by Flight; 02-16-2011 at 01:59 AM.

  7. #7
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    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:

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



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  8. #8
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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

  9. #9
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    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?



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  10. #10
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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)
    Simba Code:
    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)
    Simba Code:
    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?):
    Simba Code:
    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.

  11. #11
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    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.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  12. #12
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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.

  13. #13
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    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.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  14. #14
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Ah yes I see this part now:
    Simba Code:
    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.
    Last edited by Flight; 02-17-2011 at 11:32 AM.

  15. #15
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

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



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  16. #16
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •