SRL Archive - RS3 Help

EAccessViolation


Citrus

2015-02-26 14:02:13

EDIT: I figured out which function was causing the problem.

My script runs for ~30 minutes then crashes Simba. I don't really have any programming experience so I have no idea what to look for to fix this. I can post the script if needed but it's a bit of a mess and I would rather be told what to look for so I can find it myself.

Here is the error log.
Program exception! 
Stacktrace:

Exception class: EAccessViolation
Message: Access violation
$004100CF
$00477F97
$00598B7C
$004576F5
$00670C62
$006C0452
$0040C0B2
$0040C0B2
Simba Version: 1100

program Feathers;
{$DEFINE SMART}
{$i srl-6/srl.simba}

Const

playerName = ['player'];
playerFile = 'default';
desiredWorld = 0;

//raw chicken
RAW_COLOR = 12237455;
RAW_TOL = 9;
RAW_HUE = 5.56;
RAW_SAT = 0.96;

//fence
F_COLOR = 5138032;
F_TOL = 7;
F_HUE = 0.12;
F_SAT = 0.60;

//sack
S_COLOR = 9282221;
S_TOL = 8;
S_HUE = 0.27;
S_SAT = 0.46;

//chickens
DC_COLOR = 3957395;
DC_TOL = 20;
DC_HUE = 0.16;
DC_SAT = 0.90;

//wood
W_COLOR = 4678273;
W_TOL = 17;
W_HUE = 0.10;
W_SAT = 0.32;

//blue wall
WALL_COLOR = 11312019;
WALL_TOL = 5;
WALL_HUE = 0.38;
WALL_SAT = 0.41;

//gate
G_COLOR = 5533586;
G_TOL = 3;
G_HUE = 0.23;
G_SAT = 0.73;

//door frame
DF_COLOR = 2699584;
DF_TOL = 3;
DF_HUE = 1.01;
DF_SAT = 3.24;

var

fSlots, shaftSlots: TIntegerArray;
fDTM, cDTM, eDTM, lockDTM, sDTM, killCount, tempKillCount, fSlot, shaftSlot: integer;
gMid: TPoint;
gate: TPointArray;
hasShafts: boolean;

procedure declarePlayers();
var
i: integer;
begin
players.setup(playerName, playerFile);
currentPlayer := 0;
for i := 0 to high(players) do
begin
players[i].world := desiredWorld;
players[i].isActive := true;
writeLn('Logging in...');
end;
begin
if (not players[currentPlayer].login()) then
exit;
writeLn('Just logged in, waiting a bit...');
wait(randomRange(3000, 5000));
exitTreasure();
writeLn('Setup complete - player is logged in.');
end;
end;

procedure initPlayer();
begin
writeLn('Checking camera...');
if (minimap.getAngleDegrees() > 7) then
minimap.clickCompass()
else
writeLn('Camera already facing north');

mainScreen.setAngle(MS_ANGLE_HIGH);

writeLn('Setting run.');
if not (minimap.isRunEnabled()) then
minimap.toggleRun(true);

writeLn('Setting gametab.');
if (not gameTabs.isTabActive(TAB_BACKPACK)) then
gameTabs.openTab(TAB_BACKPACK);

writeLn('Finding feathers...');
fSlots := findItem(fDTM, tabBackPack.getSlotBoxes, true);
if length(fSlots) < 1 then
writeLn('Feathers not found.')
else
begin
fSlot := fSlots[0]+1;
writeLn(getItemAmount(tabBackPack.getSlotBox(fSlot)), ' feathers found.');
end;
writeLn('Finding shafts...');
shaftSlots := findItem(sDTM, tabBackPack.getSlotBoxes, true);
if length(shaftSlots) < 1 then
writeLn('Shafts not found.')
else
begin
shaftSlot := shaftSlots[0]+1;
hasShafts := true;
writeLn(getItemAmount(tabBackPack.getSlotBox(shaftSlot)), ' shafts found.');
end;
killCount := 0;

end;

procedure initDtms();
begin

fDTM := DTMFromString('mwQAAAHic42RgYChiYWDIAOJkKF0AxOVAXAXEDUBcC8RGTAwM+kBsC8TWQGwFxGZQMXUgVgbiJXPnAk1jwouNGAgDRiIwHAAAvvUILg==');
cDTM := DTMFromString('m1gAAAHic42JgYHBhYWBwB2I/IA4E4mAgDmCBiFsBsTUQ2wPxCUYGhj1QfACIjwDxWSC+CMTnGSHyB4F4SX8f0FQmgtiIgTjASCRGAADVCgzL');
eDTM := DTMFromString('m1gAAAHic42JgYChgYWDIAuJcIC4G4nIgLgPiPCDOgMoVAfFxRgaGg0C8F4j3AfFRID4DxBeA+AQQn4WyD3eGAU1lIoglGYgDjERiBAAA8i0ONg==');
lockDTM := DTMFromString('mwQAAAHic42RgYPjKBMGfgPgjlAbxfwLxbyD+DsTbgerWAfFGBgh7NxIG8TcB8ZWpqgwHFgcybOowZ7g1U5Nhfxc/HAtLyjPYuPszsALVEcKMRGA4AAD8TBrM');
sDTM := DTMFromString('mrAAAAHic42BgYDBhYWBQB2IdIDYCYnMgtoFiayBuY2Rg6AbiJiCeCMTtQFwH5XcBsZMaJ9AUJpyYnwE/YCSAYQAAUI0Gnw==');

writeLn('DTMs have been initalized.');
end;

function TBox.checkGate(): boolean
var
x, y: integer;
bMid: TPoint;
begin
findColorsSpiralTolerance(x, y, gate, G_COLOR, mainScreen.getBounds(), G_TOL, colorSetting(2, G_HUE, G_SAT));
self := [(self.X1+85), (self.Y2-10), (self.X2-95), (self.Y2+80)];
gate.filterPointsBox(self);
gate.sortByYValue(True);
//smartImage.debugTPA(gate);
// smartImage.drawBox(self, false, clLime);

gMid := gate.getMiddle();
bMid := self.getMiddle();
if gMid.y < (bMid.y-10) then
result := true
else
result := false;
end;

function randomThing(): boolean
var
i: integer;
begin
i := random(10)
case i of
4..9: result := true;
end;
end;

function TPointArray.filterTPA(): TPointArray;
var
x, y, i, j: integer;
fenceBox, wallBox, box, box2, playerBox, dFrameBox: TBox;
wood, fence, wall, sack, temp, dFrame: TPointArray;
ATPA, Asack, Awood: T2DPointArray;
boxes: TBoxArray;
begin
smartImage.clear();

mainscreen.filterPointsPlayer(self);

//find wall
findColorsSpiralTolerance(x, y, wall, WALL_COLOR, mainScreen.getBounds(), WALL_TOL, colorSetting(2, WALL_HUE, WALL_SAT));
//define player box
playerBox := ([mainscreen.playerPoint.X-200, mainscreen.playerPoint.Y-10, mainscreen.playerPoint.X+200, mainscreen.playerPoint.Y-140]);
//filter out wall hits below player
wall.filterPointsBox(playerBox);
// smartImage.debugTPA(wall);
wallBox := wall.getBounds();

//find fence
findColorsSpiralTolerance(x, y, fence, F_COLOR, mainScreen.getBounds(), F_TOL, colorSetting(2, F_HUE, F_SAT));
//limit fence
fence.excludePointsDist(0, 185, mainscreen.playerPoint.X, mainscreen.playerPoint.Y);
{ smartImage.debugTPA(fence); }
//define box
fenceBox := fence.getBounds();

//find door frame
findColorsSpiralTolerance(x, y, dFrame, DF_COLOR, mainScreen.getBounds(), DF_TOL, colorSetting(2, DF_HUE, DF_SAT));
dFrame.excludePointsDist(0, 50, wall.getMiddle.x, wall.getMiddle.y);
smartImage.debugTPA(dFrame);
dFrameBox := dFrame.getBounds();

//define box
box := ([wallBox.X1, dFrameBox.Y2-3, wallBox.X2, fenceBox.Y2-7]);
box.shrink(3);
if randomThing() then
begin
box2 := box.Copy();
if not box2.checkGate() then
begin
mouse(gate[0], MOUSE_MOVE, MOUSE_HUMAN);
if isMouseOverText(['lose']) then
begin
writeLn('Close the damn gate!');
fastClick(MOUSE_LEFT);
wait(randomRange(1234, 2143));
end;
end;
end;
smartImage.drawBox(box, false, clFuchsia);
//find sack
findColorsSpiralTolerance(x, y, sack, S_COLOR, mainScreen.getBounds(), S_TOL, colorSetting(2, S_HUE, S_SAT));
//remove extraneous sack points
sack.filterPointsBox(box);

//find wood
findColorsSpiralTolerance(x, y, wood, W_COLOR, mainScreen.getBounds(), W_TOL, colorSetting(2, W_HUE, W_SAT));
//remove extraneous wood points
wood.filterPointsBox(box);

//self box filter
// writeLn('Number of TPoints before box filter: ', length(self));
self.filterPointsBox(box);
// writeLn('Number of TPoints after box filter: ', length(self));

temp := sack.include(self);
// writeLn('Number of TPoints shared with sack: ', length(temp));
if length(temp) > 10 then
begin
// writeLn('Filtering sack...');
Asack := sack.toATPA(30);
Asack.filterBetween(0, 30);
boxes := Asack.getEachBounds();
// smartImage.drawBoxes(boxes, false, clAqua);

for j := 0 to high(boxes) do
begin
temp := self.copy();
temp.filterPointsBox(boxes[j]);
self := temp.exclude(self);
// writeLn('Filtered ', (j+1), ' boxes');
// writeLn('Number of TPoints after ', j+1, ' sack filters: ', length(self));
end;
end;

temp := wood.include(self);
// writeLn('Number of TPoints shared with wood: ', length(temp));
if length(temp) > 10 then
begin
// writeLn('Filtering wood...');
//wood --> Awood
Awood := splitTPA(wood, 5);
Awood.filterBetween(0, 100);
// writeLn(length(Awood), ' wood boxes found.');
boxes := Awood.getEachBounds();
// smartImage.drawBoxes(boxes, false, clYellow);

for j := 0 to high(boxes) do
begin
temp := self.copy();
temp.filterPointsBox(boxes[j]);
self := temp.exclude(self);
// writeLn('Filtered ', (j+1), ' boxes');
// writeLn('Number of TPoints after ', j+1, ' wood filters: ', length(self));
end;
end;
result := self;
end;

function track(): boolean;
var
tpa: TPointArray;
atpa: T2DPointArray;
col: TColorData;
i: integer;

begin
if isMouseOverText(['ttack']) then
exit(true);
col.color := DC_COLOR;
col.tolerance := DC_TOL;
col.settings.cts := 2;
col.settings.modifier.hue := DC_HUE;
col.settings.modifier.saturation := DC_SAT;

smartImage.clear();
col.gatherIn(tpa, mainscreen.getBounds());
tpa.filterTPA();
// smartImage.debugTPA(tpa);
atpa := splitTPA(tpa, 5);
atpa.filterBetween(0, 50);
writeLn(length(atpa), ' chickens found.');
atpa.sortFromMidPoint(mainscreen.playerPoint);
// smartImage.debugATPA(atpa);
for i := 0 to min(high(atpa), 5) do
begin
mouseBox(atpa[i].getBounds(), MOUSE_MOVE);
if isMouseOverText(['ttack']) then
begin
smartImage.clear();
exit(true);
end
else
writeLn('Too slow!');
end;
end;

function checkLock(waitTime: integer = 500): boolean;
var
x, y: integer;
t: longWord;
begin
result := false;
t := (getTimeRunning() + waitTime);
repeat
if findDTM(lockDTM, x, y, mainscreen.getBounds) then
result := true
else
wait(randomRange(40, 70));
until (getTimeRunning() >= t) or (result);
end;

procedure killChickens();
var
x, y, i, ran, failCount: integer;
chicks, lChicks: TPointArray;
Achicks: T2DPointArray
begin
while checkLock() do
begin
// writeLn('Fighting...');
wait(randomRange(400, 600));
end;
wait(randomRange(345, 678));
if track() then
begin
fastClick(MOUSE_RIGHT);
if chooseOption.select(['ttack']) then
begin
if checkLock(1234) then
begin
writeLn('Attack successful!');
inc(killCount);
inc(tempkillCount);
// writeLn('tempKillCount: ', tempKillCount);
end
else
writeLn('Attack failed.');
end;
end;
end;

procedure getFeathers();
var
x, y, i, j: integer;
cSlots, eSlots: TIntegerArray;
raw: TPointArray;
Araw: T2DPointArray;
begin
tempKillCount := 0;
// writeLn('Resetting tempKillCount.');
//code to find raw chicken
// mouseSpeed := randomRange(18, 26);

//find raw chickens
cSlots := findItem(cDTM, tabBackPack.getSlotBoxes, true);
for i := 0 to high(cSlots) do
cSlots[i] := cSlots[i]+1;
//find eggs
eSlots := findItem(eDTM, tabBackPack.getSlotBoxes, true);
for i := 0 to high(eSlots) do
eSlots[i] := eSlots[i]+1;
//drop 'em
tabBackPack.dropItems(cSlots);
tabBackPack.dropItems(eSlots);

smartImage.clear();
writeLn('getFeathers initiated. Here comes the M0N3Y!');

//raw chicken
findColorsSpiralTolerance(x, y, raw, RAW_COLOR, mainScreen.getBounds(), RAW_TOL, colorSetting(2, RAW_HUE, RAW_SAT));
//remove TPoints under feet
raw.excludePointsDist(13, 350, mainscreen.playerPoint.X, mainscreen.playerPoint.Y);
raw.filterTPA();
// smartImage.debugTPA(raw);
// writeLn('Found ', length(raw), ' raw chicken TPoints.');

Araw := raw.toATPA(13);
Araw.sortFromMidPoint(mainscreen.playerPoint);
Araw.filterBetween(0, 50);
// smartImage.debugATPA(Araw);
writeLn('Found ', length(Araw), ' raw chickens.');
wait(randomRange(111, 222));

if length(Araw) < 1 then
begin
writeLn('No dead chickens. Let''s fix that!');
repeat
killChickens();
until tempKillCount > randomRange(5, 8);
while checkLock() do
wait(randomRange(555, 777));
end;

//code to obtain feathers
j := 0;
for i := 0 to (high(Araw)-random(3)) do
begin
mouse(middleTPA(Araw[i]), MOUSE_MOVE, MOUSE_HUMAN);
if isMouseOverText(['eather'], 500) then
begin
fastClick(MOUSE_LEFT);
if tabBackpack.waitSlotPixelChange(fSlot, 3000) then
begin
writeLn('Found some feathers.');
wait(randomRange(400, 800));
smartImage.clear;
exit;
end;
end
else
begin
inc(j);
// writeLn('featherFail: ', j);
if j > (length(Araw)-3) then
begin
writeLn('Not finding any feathers. Killing time!');
repeat
killChickens();
until tempKillCount > randomRange(4, 7);
j := 0;
while checkLock() do
wait(randomRange(555, 777));
end;
end;
end;
end;

procedure makeArrows();
//var

begin
tabBackPack.mouseSlot(shaftSlot, MOUSE_MOVE);
if isMouseOverText(['eather', 'haft']) then
fastClick(MOUSE_LEFT)
else
exit;
if productionScreen.isOpen(4765) then
begin
productionScreen.selectBox(1);
wait(randomRange(300, 700));
productionScreen.clickStart();
wait(randomRange(500, 1000));
writeLn('Making headless arrows...');
repeat
wait(randomRange(999, 1234));
until not tabBackPack.waitSlotPixelChange(shaftSlot, 1500);
end;
end;

procedure scriptTerminate();
begin
freeDTM(fDtm);
freeDTM(cDTM);
freeDTM(eDTM);
freeDTM(lockDTM);
freeDTM(sDTM);
writeLn(' ');
writeln('Script time: ', timeRunning);
writeLn('Chickens killed this session: ', killCount);
{if isLoggedIn() then
players[currentPlayer].logout(); }
end;

begin
addOnTerminate('scriptTerminate');
clearDebug();
smartEnableDrawing := true;
smartShowConsole := false;
setupSRL();
disableSrlDebug := true;
mouseSpeed := randomRange(25, 35);
initDtms();
declarePlayers();
initPlayer();

while (players.getActive() > 0) do
begin
getFeathers();
while hasShafts and (getItemAmount(tabBackPack.getSlotBox(fSlot)) > 200) and (getItemAmount(tabBackPack.getSlotBox(shaftSlot)) > 200) do
makeArrows;
end;
end.

KeepBotting

2015-02-26 15:41:44

Stacktrace doesn't really tell us anything about what in your script would have causes the violation, post the script and we can try and figure it out from there

Citrus

2015-02-26 16:26:29

From: KeepBotting
Stacktrace doesn't really tell us anything about what in your script would have causes the violation, post the script and we can try and figure it out from there


Okay I added the script to my first post.

3Garrett3

2015-02-26 16:42:45

From: evilcitrus
Okay I added the script to my first post.


I don't have time to look through the code much, I didn't see anything immediately.

This type of problem (especially since it's happening after 30 minutes of run time) is typically caused by memory problems. Check anywhere that you're modifying an array and make sure you have the length set right.


SetLength(array, 1);
array[2] := 6;

This normally works at least once or twice, but then you'll call a completely unrelated function and the memory it expects to use is actually being used by Array[2] because you didn't allocate the space properly. I've had my fair share of crashes (with similar reports to yours) when I was exploring new things with arrays and not keeping track of lengths properly.

I see that you have it doing a main task and then what appears to be periodic chicken killing. Check all your periodic functions and see if they have any leaks in them, because it's normally something that would happen right away if it's a main piece of code.

Citrus

2015-02-26 16:49:22

Check all your periodic functions and see if they have any leaks in them, because it's normally something that would happen right away if it's a main piece of code.


Okay thanks. I'll check that out.