Results 1 to 13 of 13

Thread: TPA.getBounds access violation stops my script about once a day.

  1. #1
    Join Date
    Jun 2015
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    23 Post(s)

    Question TPA.getBounds access violation stops my script about once a day.

    I'm getting weird access violation error with TPA.getBounds. It stops my script everytime. How can I fix that? Here's the bit of code that I suspect is causing the error
    Simba Code:
    procedure clickWisp();
    var
      x, y, i, w, h: integer;
      TPA, riftTPA: TPointArray;
      ATPA, riftATPA: T2DPointArray;
    begin
      if findColorsSpiralTolerance(x, y, TPA, divSetting.wispCol, mainScreen.getBounds, divSetting.wispTol, colorSetting(2, divSetting.wispHue, divSetting.wispSat)) then
      begin
        ATPA := SplitTPA(TPA, 20);
        if (findColorsSpiralTolerance(x, y, riftTPA, divSetting.riftCol, mainScreen.getBounds, divSetting.riftTol, colorSetting(2, divSetting.riftHue, divSetting.riftSat))) or (findColorsSpiralTolerance(x, y, riftTPA, divSetting.blueRiftCol, mainScreen.getBounds, divSetting.blueRiftTol, colorSetting(2, divSetting.blueRiftHue, divSetting.blueRiftSat))) then
        begin
          riftATPA := SplitTPA(riftTPA, 20);
          SortATPASize(riftATPA, true);
          if debugMyATPA = True then
            smartImage.debugATPA(riftATPA);
          for i := 0 to high(ATPA) do
          begin
            if distance(ATPA[i].getBounds.getMiddle, riftATPA[0].getBounds.getMiddle) < 120 then
              ATPA.deleteIndex(i);
          end;
        end;
        if length(ATPA) < 1 then
        begin
          walkTo('wisp');
          Exit;
        end;
        ATPA.sortFromFirstPoint(mainScreen.getCenterPoint);
        if debugMyATPA = True then
          smartImage.debugATPA(ATPA);
        case random(1000) of
          0..621: instaMouse(Point((ATPA[0].getBounds.getMiddle.X)+Random(Round(-0.30*(ATPA[0].getBounds.getWidth)/2), Round(0.30*(ATPA[0].getBounds.getWidth)/2)), (ATPA[0].getBounds.getMiddle.Y)+Random(Round(-0.30*(ATPA[0].getBounds.getHeight)/2), Round(0.30*(ATPA[0].getBounds.getHeight)/2))), MOUSE_MOVE);
          622..823:
          begin
            if length(ATPA) > 1 then //2,3,4...
            begin
              instaMouse(Point((ATPA[1].getBounds.getMiddle.X)+Random(Round(-0.30*(ATPA[1].getBounds.getWidth)/2), Round(0.30*(ATPA[1].getBounds.getWidth)/2)), (ATPA[1].getBounds.getMiddle.Y)+Random(Round(-0.30*(ATPA[1].getBounds.getHeight)/2), Round(0.30*(ATPA[1].getBounds.getHeight)/2))), MOUSE_MOVE);
            end else
              instaMouse(Point((ATPA[0].getBounds.getMiddle.X)+Random(Round(-0.30*(ATPA[0].getBounds.getWidth)/2), Round(0.30*(ATPA[0].getBounds.getWidth)/2)), (ATPA[0].getBounds.getMiddle.Y)+Random(Round(-0.30*(ATPA[0].getBounds.getHeight)/2), Round(0.30*(ATPA[0].getBounds.getHeight)/2))), MOUSE_MOVE);
          end;
          824..999:
          begin
            if length(ATPA) > 2 then //3,4,5...
            begin
              instaMouse(Point((ATPA[2].getBounds.getMiddle.X)+Random(Round(-0.30*(ATPA[2].getBounds.getWidth)/2), Round(0.30*(ATPA[2].getBounds.getWidth)/2)), (ATPA[2].getBounds.getMiddle.Y)+Random(Round(-0.30*(ATPA[2].getBounds.getHeight)/2), Round(0.30*(ATPA[2].getBounds.getHeight)/2))), MOUSE_MOVE);
            end else
              instaMouse(Point((ATPA[0].getBounds.getMiddle.X)+Random(Round(-0.30*(ATPA[0].getBounds.getWidth)/2), Round(0.30*(ATPA[0].getBounds.getWidth)/2)), (ATPA[0].getBounds.getMiddle.Y)+Random(Round(-0.30*(ATPA[0].getBounds.getHeight)/2), Round(0.30*(ATPA[0].getBounds.getHeight)/2))), MOUSE_MOVE);
          end;
        end;
        if isMouseOverText(divSetting.wispUpText) then
        begin
          case random(1000) of
            0..764:
            begin
              fastClick(mouse_Left);
              if didRedClick() then
                afterClick();
            end;
            765..974:
            begin
              fastClick(mouse_Right);
              Wait(RandomRange(45, 148));
              if chooseOption.Select(divSetting.wispUpText) then
                afterClick();
            end;
            975..999:
            begin
              fastClick(mouse_Right);
              Wait(RandomRange(45, 148));
              if chooseOption.Select(['alk here']) then
                waitMissClick();
            end;
          end;
        end else
          walkTo('wisp');
      end else
        walkTo('wisp');
    end;

    procedure clickRift();
    var
      x, y, tries: integer;
      TPA: TPointArray;
      ATPA: T2DPointArray;
    begin
      if (findColorsSpiralTolerance(x, y, TPA, divSetting.RiftCol, mainScreen.getBounds, divSetting.RiftTol, colorSetting(2, divSetting.RiftHue, divSetting.RiftSat))) or (findColorsSpiralTolerance(x, y, TPA, divSetting.blueRiftCol, mainScreen.getBounds, divSetting.blueRiftTol, colorSetting(2, divSetting.blueRiftHue, divSetting.blueRiftSat))) then
      begin
        ATPA := SplitTPA(TPA, 20);
        SortATPASize(ATPA, true);
        if debugMyATPA = True then
          smartImage.debugATPA(ATPA);
        if length(ATPA) > 0 then
          instaMouse(Point((ATPA[0].getBounds.getMiddle.X)+Random(Round(-0.30*(ATPA[0].getBounds.getWidth)/2), Round(0.30*(ATPA[0].getBounds.getWidth)/2)), (ATPA[0].getBounds.getMiddle.Y)+Random(Round(-0.30*(ATPA[0].getBounds.getHeight)/2), Round(0.30*(ATPA[0].getBounds.getHeight)/2))), MOUSE_MOVE);
        if isMouseOverText(divSetting.riftUpText) then
        begin
          fastClick(mouse_Right);
          Wait(RandomRange(45, 148));
          case convertTo of
            'exp':
            begin
              case Random(1000) of
                0..950:
                begin
                  if chooseOption.select(['o experience']) then
                    afterClick();
                end;
                951..975:
                begin
                  if chooseOption.select(['o energy']) then
                    waitMissClick();
                end;
                976..999:
                begin
                  if chooseOption.select(['nhanced experience']) then
                    waitMissClick();
                end;
              end;
            end;
            'energy':
            begin
              case Random(1000) of
                0..975:
                begin
                  if chooseOption.select(['o energy']) then
                    afterClick();
                end;
                976..999:
                begin
                  if chooseOption.select(['o experience']) then
                    waitMissClick();
                end;
              end;
            end;
          end;
        end else
          walkTo('rift');
      end else
        walkTo('rift');
    end;

  2. #2
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    .getBounds.getMiddle.X -> .getBounds().getMiddle().X

  3. #3
    Join Date
    Jun 2015
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    23 Post(s)

    Default

    Are you certain that this is causing an error once every 10 hours?

  4. #4
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by wedmarco View Post
    Are you certain that this is causing an error once every 10 hours?
    No, if it occurs randomly then it is a completely different problem. I thought by 'everytime' you meant it didn't compile. It is probably trying to access an index that is out of range or something. Probably when you are deleting indices of the ATPA. Try using downto instead.

    In general though, the procedure seems overly complicated to click on a wisp?

  5. #5
    Join Date
    Oct 2012
    Posts
    1,258
    Mentioned
    40 Post(s)
    Quoted
    588 Post(s)

    Default

    Skimmed the code, probably due to ATPA.deleteIndex(i) deleting a TPA and the code then trying to find a TPA that doesn't exist.
    Quote Originally Posted by Laquisha View Post
    In general though, the procedure seems overly complicated to click on a wisp?
    Divination is a high banrate area, people like to add things in to mix stuff up in situations like that.

  6. #6
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by acow View Post
    Skimmed the code, probably due to ATPA.deleteIndex(i) deleting a TPA and the code then trying to find a TPA that doesn't exist.

    Divination is a high banrate area, people like to add things in to mix stuff up in situations like that.
    I understand that, I'm just saying there are simplier ways to write some of the 'random' things in the script. Complex/messy code doesn't really matter unless you need to debug something (like in this case) or other people need to read the code (like in this case too).

    For example: instead of getting the midpoint of each ATPA, and then randomizing the x and y and then passing them back to Point(), why not just .getBounds().getRandomPoint()?

    So the whole thing might just look like: instaMouse(ATPA[random(length(ATPA))].getBounds().getRandomPoint()

    Just a suggestion.

  7. #7
    Join Date
    Jun 2015
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    23 Post(s)

    Default

    Is there a way to remove ''holes'' that are created when I delete an ATPA index? For example if I have ATPA[0], ATPA[1] and ATPA[2] and I delete ATPA[1], can the ATPA be reformated so that there's only ATPA[0], ATPA[1] (formally ATPA[0] and ATPA[2])?

  8. #8
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by wedmarco View Post
    Is there a way to remove ''holes'' that are created when I delete an ATPA index? For example if I have ATPA[0], ATPA[1] and ATPA[2] and I delete ATPA[1], can the ATPA be reformated so that there's only ATPA[0], ATPA[1] (formally ATPA[0] and ATPA[2])?
    This has already been answered in this thread. Use downto.

    Simba Code:
    for I := High(ATPA) downto 0 do
    Last edited by Kasi; 09-02-2016 at 10:02 PM.

  9. #9
    Join Date
    Jun 2015
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    23 Post(s)

    Default

    Can you explain what downto does? Do I have to create a new for to do loop?

  10. #10
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by wedmarco View Post
    Can you explain what downto does? Do I have to create a new for to do loop?
    Simba Code:
    for I := High(ATPA) downto 0 do

    Simba Code:
    for I := 0 to High(ATPA) do

  11. #11
    Join Date
    Jun 2015
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    23 Post(s)

    Default

    Can you explain how this would help my problem in any ways? It doesn't matter if it starts sorting from the highest to the lowest or the lowest to the highest...

  12. #12
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by wedmarco View Post
    Can you explain how this would help my problem in any ways? It doesn't matter if it starts sorting from the highest to the lowest or the lowest to the highest...
    ....

    At the moment you are getting access violations because you're accessing memory that isn't yours to access.

    For example you have an array with the length of 5 and you had to delete the 4th value. Array[0], Array[1], Array[2], Array[3](this element), Array[4].
    Your for loop would iterate like so... I = 0, I = 1, I = 2, I = 3, I = 4.

    if you were to delete index 3 (the 4th value). You would loop through, until I = 3. When I is 3; you remove that index, the new size of the array is now 4. Your for loop, iterating from 0-4 inclusive would try to access index 4 in it's next iteration. There is a problem here because Array[4] no longer exists, Bam! Access violation. It was moved to Array[3] because you deleted the original Array[3].

    You wouldn't have this problem with downto because you are iterating down to 0. I = 4, I = 3, I = 2, I = 1, I = 0. The next iteration will ALWAYS be in range and accessible. If you still don't understand, Try to figure out this while loop with your own logic and compare it to the for loop iterating upwards.

    Simba Code:
    I = 0;
    while (I < Length(Array)) do
    begin
      if (WantToRemoveIndex) then
        RemoveIndex(I)
      else
        Inc(I);
    end;
    Last edited by Kasi; 09-03-2016 at 09:12 AM.

  13. #13
    Join Date
    Jun 2015
    Posts
    69
    Mentioned
    0 Post(s)
    Quoted
    23 Post(s)

    Default

    Thank you so much for explaining it. I really didn't think this one through

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
  •