Results 1 to 9 of 9

Thread: Access violation within TReflectActor.getQueueSize

  1. #1
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default Access violation within TReflectActor.getQueueSize

    I'm getting an access violation on line 21 in Actor.simba (third line down):
    Simba Code:
    function TReflectActor.GetQueueSize: Integer;
    begin
      if Reflect.Smart.IsNull(Self.Reference) then
        Exit(-1);
      Result := Reflect.Smart.GetFieldInt(Self.Reference, Actor_QueueSize);
    end;

    This seems to be the culprit in my script, however I cannot pinpoint why this error occurs:

    Simba Code:
    procedure p_nearPortal();
    var
      NPCs : TReflectNPCArray;
      i : Integer;
      Portal_ : treflectnpc;
      PortalPoint : TPointArray;
    begin
      if f_inCombat then Exit;
      NPCs.GetAll();
      if length(NPCs) = 0 then Exit;
      NPCs.Sort();
      for i := 0 to High(Portals) do
      begin
        if Portals[i].isShieldDown then
        begin
          if Portal_.Find(Portals[i].ID) then
          begin
            if not Portal_.IsOnMS then
            begin
              SetLength(PortalPoint, 1);
              PortalPoint[0] := Portal_.GetTile;
              RandomizeTPA(PortalPoint, 3, 3);
              case random(5) of
              0..3: Me.BlindWalkMS(PortalPoint[0]);
              4..5 : Me.BlindWalkMM(PortalPoint[0]);
              end;
            end;
            R_InteractTile(Portal_.getTile, ['Attack']);
            Exit;
          end;
        end;
      end;
      for i := 0 to High(NPCs) do
      begin
        if NPCs[i].getMaxHealth = 0 then
          Continue;
        if ((Pos(Lowercase(NPCs[i].getName), 'spin') > 0) and ((NPCs[i].getHealth/NPCs[i].getMaxHealth) > 0.7)) then
        begin
          R_InteractTile(NPCs[i].getTile, ['Attack']);
          Exit;
        end;
       if (NPCs[i].getHealth/NPCs[i].getMaxHealth) > 0.7 then
       begin
        R_InteractTile(NPCs[i].getTile, ['Attack']);
        Exit;
       end;
      end;
    end;
    "Once you begin to think, you can't stop."

    Life > 0

  2. #2
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    @kristi; Well it's tough to tell for sure, not having more code, but i'm guessing it is with your global "Portals" array. Assuming that is a TReflectNpc, it is definitely your problem. The way the include works, is when you call a .Find/.Get method for any object (NPC, In Game object) it frees all the instances of that type of object.
    For example:
    Simba Code:
    Npc1, Npc2: TReflectNpc;
    begin
      Npc1.Find('Man');
      WriteLn(Npc1.GetName); //Perfectly OK
      Npc2.Find('Man'); //Npc1 is now freed
      WriteLn(Npc1.GetName); //Will eventually cause an error since Npc1 points to garbage in memory
      WriteLn(Npc2.GetName); //Perfectly OK
    end;
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  3. #3
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Default

    Quote Originally Posted by Kyle View Post
    @kristi; Well it's tough to tell for sure, not having more code, but i'm guessing it is with your global "Portals" array. Assuming that is a TReflectNpc, it is definitely your problem. The way the include works, is when you call a .Find/.Get method for any object (NPC, In Game object) it frees all the instances of that type of object.
    For example:
    Simba Code:
    Npc1, Npc2: TReflectNpc;
    begin
      Npc1.Find('Man');
      WriteLn(Npc1.GetName); //Perfectly OK
      Npc2.Find('Man'); //Npc1 is now freed
      WriteLn(Npc1.GetName); //Will eventually cause an error since Npc1 points to garbage in memory
      WriteLn(Npc2.GetName); //Perfectly OK
    end;
    Huh, weird. The portal array is merely an array of my TPortal type which stores the data for the different portals:
    Simba Code:
    type
      TPortal = record
        Name : String;
        Tile,
        GateTile : TPoint;
        ID,
        WidgetChild,
        WidgetChild2,
        Health : Integer;
        ShieldBox : TBox;
      end;

    But I don't see anywhere in the code where I'm trying to access a previous instance of the portal? Or maybe I misunderstood, please fill me in
    "Once you begin to think, you can't stop."

    Life > 0

  4. #4
    Join Date
    Aug 2007
    Posts
    539
    Mentioned
    20 Post(s)
    Quoted
    266 Post(s)

    Default

    From looking at the code you provided, the only instance where TReflectActor.GetQueueSize would be used with:
    Simba Code:
    0..3: Me.BlindWalkMS(PortalPoint[0]);
              4..5 : Me.BlindWalkMM(PortalPoint[0]);

    I'm guessing your TReflectLocalPlayer ('Me') isn't '.Create'ed?

    Also you are calling 'NPCs.GetAll();' and later within the code you are using 'Portal_.Find(Portals[i].ID)', a get npc function, and then later you are trying to access data from the 'NPCs' array which would crash SMART and give errors as Kyle mentioned.
    Discord: Guy#1693

  5. #5
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    269
    Mentioned
    17 Post(s)
    Quoted
    161 Post(s)

    Red face

    Quote Originally Posted by ineedbot View Post
    From looking at the code you provided, the only instance where TReflectActor.GetQueueSize would be used with:
    Simba Code:
    0..3: Me.BlindWalkMS(PortalPoint[0]);
              4..5 : Me.BlindWalkMM(PortalPoint[0]);

    I'm guessing your TReflectLocalPlayer ('Me') isn't '.Create'ed?

    Also you are calling 'NPCs.GetAll();' and later within the code you are using 'Portal_.Find(Portals[i].ID)', a get npc function, and then later you are trying to access data from the 'NPCs' array which would crash SMART and give errors as Kyle mentioned.
    It should be created, Me.Create is called in the script's initialization procedure(also weird because walking doesn't return any errors otherwise). The rest of the code is pretty badly throw together, it's a WIP . Will have to get a second look when I get home, but thanks for the help! (And @Kyle)
    "Once you begin to think, you can't stop."

    Life > 0

  6. #6
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Quote Originally Posted by Kyle View Post
    @kristi; Well it's tough to tell for sure, not having more code, but i'm guessing it is with your global "Portals" array. Assuming that is a TReflectNpc, it is definitely your problem. The way the include works, is when you call a .Find/.Get method for any object (NPC, In Game object) it frees all the instances of that type of object.
    For example:
    Simba Code:
    Npc1, Npc2: TReflectNpc;
    begin
      Npc1.Find('Man');
      WriteLn(Npc1.GetName); //Perfectly OK
      Npc2.Find('Man'); //Npc1 is now freed
      WriteLn(Npc1.GetName); //Will eventually cause an error since Npc1 points to garbage in memory
      WriteLn(Npc2.GetName); //Perfectly OK
    end;
    Ah ha!

    This is a separate issue but I suppose the explanation is the same.

    I've been getting crashes when using something like below:

    Simba Code:
    i, j, idx: Integer;
    playerArr1, playerArr2: TReflectPlayerArray;
    begin
      playerArr1.GetAll;
      for i:=0 to High(playerArr1) do
      begin
        idx := playerArr1[i].GetInteractingIndex();
        playerArr2.Get(idx); // overloaded the Get() method to use the player's index (integer)
        for j:=0 to High(playerArr2) do
        begin
          writeln(playerArr1[i].GetName() + ' is interacting with ' + playerArr2[j].GetName());
        end;
      end;
    end;

    If I understand what you're saying the crashes are as a result of playerArr1[i] pointing to a location in memory that has since been cleaned up by the garbage collector. As a result, calling any methods (ie. GetName()) result in the crashes.

    It seems to me I would have to write out the index of each player found to a locally stored variable before calling another Get().

  7. #7
    Join Date
    Apr 2007
    Posts
    373
    Mentioned
    2 Post(s)
    Quoted
    24 Post(s)

    Default

    I am getting the same error when using BlindWalkMS, if i use BlindWalkMM there is no problem.
    Note: that the original code is not mine.


    Simba Code:
    procedure chopTree;
    var tempTree : TreeObject;
        rSTile : Tpoint;
        tempObject : TReflectObject;
        i, objectID : integer;
        _objects : TReflectobjecTArray;
        tempTrees : TreeObjectArray;
    begin

      Debug('Looking for tree...');
      tempTree.Tile.X := 0;


      tempTrees := UseLocation.TreeObjects.getAliveTrees;
      if length(tempTrees) <> 0 then begin
        tempTree := tempTrees.getClosestTree;
      end else begin
        tempTrees := UseLocation.TreeObjects.getDeadTrees;
        if length(tempTrees) <> 0 then
        begin
          tempTree := UseLocation.TreeObjects.getClosestTreeTime;
          if tempTree.isValid then
          begin
          if not R_TileOnMS(tempTree.Tile, rsTile, tempTree.Offset[0], tempTree.Offset[1], tempTree.Offset[2]) then
            if not Reflect.Tiles.NearTile(TempTree.Tile, 5) then
            begin
              locPlayer.BlindWalkMM(Point(tempTree.Tile.x + tempTree.TileOffset[0], tempTree.Tile.y + tempTree.TileOffset[1]), 5);
              locPlayer.FFlag(2+randomRange(-2, 2), 5000+random(500));
              sleep(random(1500));
            end;
            tempTree.Tile.X := 0;
          end;
        end else
          exit;
      end;



      if tempTree.isValid then
      begin
        PreviousTree := UseLocation.TreeObjects.getClosestTree;
        Debug('Going to chop tree.');
        if not R_TileOnMS(tempTree.Tile, rsTile, tempTree.Offset[0], tempTree.Offset[1], tempTree.Offset[2]) then
        begin
          // if i use locPlayer.BlindWalkMS the error occurs
          locPlayer.BlindWalkMM(Point(tempTree.Tile.x + tempTree.TileOffset[0], tempTree.Tile.y + tempTree.TileOffset[1]), 5);
          locPlayer.FFlag(2+randomRange(-2, 2), 5000+random(500));
          sleep(random(1500));
        end;

        Reflect.Interfaces.CloseAll;

        if R_TileOnMS(tempTree.Tile, rsTile, tempTree.Offset[0], tempTree.Offset[1], tempTree.Offset[2]) then
        begin
          if R_InteractTile(tempTree.Tile, tempTree.Options, tempTree.Offset[0], tempTree.Offset[1], tempTree.Offset[2]) then
          begin
            sleep(random(1000));
            locPlayer.FFlag(0, 5000+random(500));
            sleep(1000+random(1000));
            tempObject.GetAt(ObjGame, tempTree.Tile);
            if not Reflect.Smart.IsNull(tempObject.Reference) then
              objectID := tempObject.GetId
            else
              objectID := -1;
            while locPlayer.IsLoggedIn and inIntArray(TempTree.AliveIDs, objectID) and
                  (inIntArray(ChopAnimationIDs, locPlayer.GetAnimation)) and
                  not Reflect.Inv.IsFull and not locPlayer.IsUnderAttack do
            begin
              randomHandler;
              FixActive;
              Debug('Chopping tree...');
              tempObject.GetAt(ObjGame, tempTree.Tile);
              if not Reflect.Smart.IsNull(tempObject.Reference) then
                objectID := tempObject.GetId
              else
                objectID := -1;
            end;
          end;
        end;
      end;
    end;
    Last edited by fre; 10-16-2016 at 11:30 PM.
    ~Fre

  8. #8
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    Quote Originally Posted by fre View Post
    ..
    Did it just start happening after the most recent rs update?
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  9. #9
    Join Date
    Apr 2007
    Posts
    373
    Mentioned
    2 Post(s)
    Quoted
    24 Post(s)

    Default

    No idea, i just started working with this code.
    ~Fre

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
  •