SRL Archive - Bugs

Simba Crashing During Runtime


3Garrett3

2010-08-24 13:23:43

It doesn't give any errors, and I'm trying to get MSI's fishing to work, but I can't test because something in the code makes it fail/freeze/crash.

Here is the code:


{==============================================================================\
| MSI Group Scripting Include |
| Fishing.scar |
|==============================================================================|
| For all fishing routines. |
| |
| * function MSI_FishingTools() * by 3Garrett3 |
| * function MSI_DetectWaterDirections(); * by 3Garrett3 |
| * function MSI_DetectSide(); * by 3Garrett3 |
| * function MSI_FishPixels(); * by 3Garrett3 |
| * function MSI_FishGear(); * by 3Garrett3 |
| * procedure MSI_WaitWhileFishing(); * by 3Garrett3 |
| * function MSI_Fish(); * by 3Garrett3 |
| * function MSI_FishInvFull(); * by 3Garrett3 |
| |
| |
\ _____________________________________________________________________________}

{******************************************************************************}
{ Function MSI_FishingTools : TIntegerArray }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Figures out which tool the script needs to use }
{******************************************************************************}
Function MSI_FishingTools : TIntegerArray;
var
script: TScript;
i: Integer;
begin
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];

for i := 0 to High(script.Objects) do
case (script.Objects[i]) of
FISHSPOT_NET:
Result := CombineIntArray(Result, [FISH_SMALLNET]);

FISHSPOT_BAIT:
Result := CombineIntArray(Result, [FISH_ROD, FISH_BAIT]);

FISHSPOT_LURE:
Result := CombineIntArray(Result, [FISH_FLY, FISH_FEATHER]);

FISHSPOT_CAGE:
Result := CombineIntArray(Result, [FISH_CAGE]);

FISHSPOT_HARPOON:
Result := CombineIntArray(Result, [FISH_HARPOON]);

else
MSI_Debug('MSI_FishingTools', 'Invalid Fishing Spot', DEBUG_FUNCTIONS);
end;

ClearSameIntegers(Result);
end;

{******************************************************************************}
{ Function MSI_DetectWaterDirections() : TBoolArray }
{ By: 3Garrett3 }
{ Date: 24 August 2010 }
{ Description: Finds the directions of water, helping find the fishing spot }
{******************************************************************************}
Function MSI_DetectWaterDirections(var Counts : TIntegerArray) : TBoolArray; // Array - 0 = right 1 = left 2 = below 3 = above
var
ATPA : T2DPointArray;
cts, i : Integer;
begin
SetLength(ATPA, 4);
SetLength(Result, 4);

cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.25, 0.25);

FindColorsTolerance(ATPA[0], 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14); // To the right
FindColorsTolerance(ATPA[1], 9602689, MSCx - 40 , MSCy - 10, MSCx - 20, MSCy + 10, 14); // To the left
FindColorsTolerance(ATPA[2], 9602689, MSCx - 10 , MSCy + 30, MSCx + 10, MSCy + 50, 14); // below
FindColorsTolerance(ATPA[3], 9602689, MSCx - 10 , MSCy - 50, MSCx + 10, MSCy - 30, 14); // above

for i := 0 to 3 do
begin
Result[i] := (Length(ATPA[i]) > 200);
Counts[i] := Length(ATPA[i]);
end;

ColorToleranceSpeed(cts);
end;

{******************************************************************************}
{ Function MSI_DetectSide : String }
{ By: 3Garrett3 }
{ Date: 24 August 2010 }
{ Description: Finds the direction of a fishing spot and returns compass angle }
{******************************************************************************}
Function MSI_DetectSide : String;
var
Water : TBoolArray;
Right, Left, Above, Below : Boolean;
i, TrueCount, cts : Integer;
WaterCount : TIntegerArray;
TPA : TpointArray;
begin
SetLength(Water, 4);
SetLength(WaterCount, 4);
Water := MSI_DetectWaterDirections(WaterCount);

for i := 0 to 3 do
if Water[i] then Inc(TrueCount);

if TrueCount = 1 then
begin
for i := 0 to 3 do
case i of
0: //right
if Water[i] then
begin
Result := 'n';
Exit;
end;
1: // left
if Water[i] then
begin
Result := 's';
Exit;
end;
2: // below
if Water[i] then
begin
Result := 'e';
Exit;
end;
3: // above
if Water[i] then
begin
Result := 'w';
Exit;
end;
end; // This means if there is only water on one side, there can only be fish on one side
// The camera angle is set as the result, it will allow for only one search box (the right side of char)
end;

Right := Water[0]; // For me to not get confused, if someone else does work they can make this prettier and stuff
Left := Water[1];
Below := Water[2];
Above := Water[3];

cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.25, 0.25);

if Right then
begin
MakeCompass('n');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 'n';
Exit;
end;
end;

if Left then
begin
MakeCompass('s');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 's';
Exit;
end;
end;

if Above then
begin
MakeCompass('w');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 'w';
Exit;
end;
end;

if Below then
begin
MakeCompass('e');
FindColorsTolerance(TPA, 9602689, MSCx + 20 , MSCy - 10, MSCx + 40, MSCy + 10, 14);
if not InRange(Length(TPA), WaterCount[0] - 30, WaterCount[0] + 30) then
begin
Result := 'e';
Exit;
end;;
end;
end;

{******************************************************************************}
{ Procedure MSI_FishPixels }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Detects the pixelshift to decide if fishing }
{******************************************************************************}
Function MSI_FishPixels(TWait, TCount : Integer; TTBox : TBox) : Boolean;
var
Shifts, FinalCount, Waiting : Integer;
ShiftsArray : TIntegerArray;
begin
MarkTime(Waiting);
While TimeFromMark(Waiting) <= TWait do
begin
Shifts := PixelShift(TTBox, 500);
CombineIntArray(ShiftsArray, [Shifts]);
Wait(RandomRange(50,75));
end;

FinalCount := AverageTIA(ShiftsArray);
Result := (FinalCount >= TCount);
end;

{******************************************************************************}
{ Procedure MSI_FishGear }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Detects fishing gear on the screen }
{******************************************************************************}
Function MSI_FishGear(TColour, TTol, TCount, TWait : Integer; THue, TSat : Extended; TTBox : TBox) : Boolean;
var
FinalCount, Waiting, cts : Integer;
ToolAmount : TIntegerArray;
Tools : TPointArray;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(THue, TSat);

MarkTime(Waiting);
While TimeFromMark(Waiting) <= TWait do
begin
FindColorsSpiralTolerance(MMCX, MMCY, Tools, TColour, TTBox.X1, TTBox.Y1, TTBox.X2, TTBox.Y2, TTol);
CombineIntArray(ToolAmount, [Length(Tools)]);
Wait(RandomRange(50,75));
end;

FinalCount := AverageTIA(ToolAmount);
Result := (FinalCount >= TCount);
ColorToleranceSpeed(cts);
end;

{******************************************************************************}
{ Procedure MSI_WaitWhileFishing }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Waits while fishing }
{******************************************************************************}
procedure MSI_WaitWhileFishing;
var
OldInvCount, WaitTime, InvTimer, cts, i : Integer;
SearchBox : TBox;
script: TScript;
TColour, TTol, TCount, TWait : Integer;
THue, TSat : Extended;
TPixel, Fishing : Boolean;
begin
Flag;
Wait(RandomRange(300, 450));
if InvFull then
Exit;

SearchBox := IntToBox(270, 148, 296, 180);
MakeCompass(MSI_DetectSide);


script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
TPixel := False;

case (script.Objects[i]) of
FISHSPOT_NET:
begin
TPixel := True;
TCount := 150;
TWait := 3300;
end;

FISHSPOT_BAIT:
begin
TColour:= 727589;
TTol := 4;
THue := 0.17;
TSat := 0.65;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_LURE:
begin
TColour:= 859433;
TTol := 3;
THue := 0.19;
TSat := 1.11;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_CAGE:
begin
TPixel := True;
TCount := 150;
TWait := 3600;
end;

FISHSPOT_HARPOON:
begin
TPixel := True;
TCount := 160;
TWait := 3000;
end;
end;

WaitTime := GetSystemTime + 90000;
OldInvCount := InvCount;
MarkTime(InvTimer);

repeat

MSI_FindRandoms;
MSI_AntiBan(RandomRange(0, 3000), ANTI_BAN_CHANCE);

if InvFull then break;

if (TimeFromMark(InvTimer) > 30000) then // If no new fish in inv after 30 seconds, spot probably moved
if (OldInvCount = InvCount) then break
else begin
OldInvCount := InvCount;
MarkTime(InvTimer);
end;

if TPixel then
Fishing := MSI_FishPixels(TWait, TCount, SearchBox)
else
Fishing := MSI_FishGear(TColour, TTol, TCount, TWait, THue, TSat, SearchBox);
if not Fishing then break;

Wait(RandomRange(200, 500));

until(WaitTime > GetSystemTime)
end;

{******************************************************************************}
{ Function MSI_Fish : Boolean }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Finds the fishing spot }
{******************************************************************************}
function MSI_Fish(Which: TIntegerArray): Boolean;
var
Fish: TMSObjectArray;
SearchBox: TBox;
Index: Integer;
begin
Fish := MSI_GetObjects(Which);
SearchBox := MSBox;

if MSI_FindObjectsIn(Fish, Index, SearchBox, ClickLeft) then
begin
Result := True;
MSI_WaitWhileFishing;
end;
end;

{******************************************************************************}
{ Function MSI_FishInvFull : Boolean }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Fishes until full inventory }
{******************************************************************************}
function MSI_FishInvFull(Which: TIntegerArray): Boolean;
var
t: Integer;
Begin
t := (GetSystemTime + (10 * 60000));
while (not InvFull) and (LoggedIn) and (GetSystemTime < T) do
begin
if MSI_Fish(Which) then
t := (GetSystemTime + (5 * 60000));
Wait(RandomRange(300, 800));
end;
Result := InvFull;
end;

The crash happens during MSI_WaitWhileFishing, but I'm not sure what part. During the repeat loop is my guess. It makes it past the changing compass angle part, so it must be during the waiting. It might be because of the Pixelshift part, but I can't be sure.

Heavenguard

2010-08-24 20:39:01

hmm.. i really don't see why this would crash to be honest, I mean to me theres nothing so fatal to make it crash at all =/

Cstrike

2010-08-24 20:56:01

I wonder if the code "script.Objects" could be making it crashing. If I ever mess up an array without knowing it, my script goes really screwy. Half the time I'll get a nice warning that it's exceeded a certain length, other times it will flat out say "screw you" to me and crash.

i luffs yeww

2010-08-24 21:22:54

Garrett told me he tried using a bunch of try..excepts but it still crashed (even with the whole thing try..except'd).

Coh3n

2010-08-25 00:38:52

You're missing a couple semicolons in WaitWhileFishing, although I seriously doubt that would cause Simba to crash. You also have a lot of repeating code that could be much better done with types and such. I'm sure you know that and just want to get something testable, so I'll leave you alone for now. :p

Blumblebee

2010-08-25 01:25:11

try removing parts of the code until it compiles and doesn't crash, allowing you to find out the issue?

Wizzup?

2010-08-25 03:29:38

From: Blumblebee
try removing parts of the code until it compiles and doesn't crash, allowing you to find out the issue?


That's a good piece of advice. I can't find the error with a quick glance either. Do you use reflection?

3Garrett3

2010-08-25 04:28:42

No, this is 100% colour.

I should have some free time later today to debug this I hope..

@Cohen,
That was my goal exactly. It's messy/ugly but the important thing was that it would work, and it doesn't :P

Coh3n

2010-08-26 00:34:46

From: 3Garrett3
No, this is 100% colour.

I should have some free time later today to debug this I hope..

@Cohen,
That was my goal exactly. It's messy/ugly but the important thing was that it would work, and it doesn't :P

Yeah sorry I haven't been much help. I've been moving the last couple days and hockey/school is starting so I'll be busier, but I'll still be around.

Daniel

2010-08-26 03:54:02

It would be nice if you could debug via breakpoints ;)

But apart from that, you'd just have to comment out and remove each line of code (un-commenting the previous) until it doesn't crash anymore. Which would be a pain in the ass, I know :/

Sir R. M8gic1an

2010-08-31 22:25:50

Guys, why the hell remove code… ?


const
MAX_FISH_WAIT = 30000;

{******************************************************************************}
{ Procedure MSI_WaitWhileFishing }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Waits while fishing }
{******************************************************************************}
procedure MSI_WaitWhileFishing;
var
OldInvCount, WaitTime, InvTimer, cts, i : Integer;
SearchBox : TBox;
script: TScript;
TColour, TTol, TCount, TWait : Integer;
THue, TSat : Extended;
TPixel, Fishing : Boolean;
begin

if InvFull then exit;

MSI_AddHeader('MSI_WaitWhileFishing');

Flag;
Wait(RandomRange(300, 450));

MSI_Debug('Detecting Side');
SearchBox := IntToBox(270, 148, 296, 180);
MakeCompass(MSI_DetectSide);

MSI_Debug('Getting Script Information');
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
TPixel := False;

case (script.Objects[i]) of
FISHSPOT_NET:
begin
TPixel := True;
TCount := 150;
TWait := 3300;
end;

FISHSPOT_BAIT:
begin
TColour:= 727589;
TTol := 4;
THue := 0.17;
TSat := 0.65;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_LURE:
begin
TColour:= 859433;
TTol := 3;
THue := 0.19;
TSat := 1.11;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_CAGE:
begin
TPixel := True;
TCount := 150;
TWait := 3600;
end;

FISHSPOT_HARPOON:
begin
TPixel := True;
TCount := 160;
TWait := 3000;
end;
end;

MSI_Debug('Initializing vars');
WaitTime := GetSystemTime + 90000;
OldInvCount := InvCount;
MarkTime(InvTimer);

MSI_AddHeader('Starting Loop');
repeat
MSI_Debug('Randoms Check');
MSI_FindRandoms;
MSI_AntiBan(RandomRange(0, 3000), ANTI_BAN_CHANCE);

if InvFull then break;

// If no new fish in inv after 30 seconds, spot probably moved
MSI_Debug('InvTime check');
if (TimeFromMark(InvTimer) > MAX_FISH_WAIT) then
if (OldInvCount = InvCount) then
break
else begin
OldInvCount := InvCount;
MarkTime(InvTimer);
end;

MSI_Debug('TPixel check: ' + BoolToStr(TPixel));
if TPixel then
Fishing := MSI_FishPixels(TWait, TCount, SearchBox)
else
Fishing := MSI_FishGear(TColour, TTol, TCount, TWait, THue, TSat, SearchBox);

if not Fishing then break;

Wait(RandomRange(200, 500));

until(WaitTime > GetSystemTime)
MSI_CloseHeader('Ending Loop');

MSI_CloseHeader('WaitWhileFishing: Exiting');
end;

Just debug it >.> Look at where the debug ended and you'll know where it stopped.
MSI saves all the debugs to file… ;)

~RM

3Garrett3

2010-08-31 22:41:59

From: Sir R. Magician
Guys, why the hell remove code… ?


const
MAX_FISH_WAIT = 30000;

{******************************************************************************}
{ Procedure MSI_WaitWhileFishing }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Waits while fishing }
{******************************************************************************}
procedure MSI_WaitWhileFishing;
var
OldInvCount, WaitTime, InvTimer, cts, i : Integer;
SearchBox : TBox;
script: TScript;
TColour, TTol, TCount, TWait : Integer;
THue, TSat : Extended;
TPixel, Fishing : Boolean;
begin

if InvFull then exit;

MSI_AddHeader('MSI_WaitWhileFishing');

Flag;
Wait(RandomRange(300, 450));

MSI_Debug('Detecting Side');
SearchBox := IntToBox(270, 148, 296, 180);
MakeCompass(MSI_DetectSide);

MSI_Debug('Getting Script Information');
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
TPixel := False;

case (script.Objects[i]) of
FISHSPOT_NET:
begin
TPixel := True;
TCount := 150;
TWait := 3300;
end;

FISHSPOT_BAIT:
begin
TColour:= 727589;
TTol := 4;
THue := 0.17;
TSat := 0.65;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_LURE:
begin
TColour:= 859433;
TTol := 3;
THue := 0.19;
TSat := 1.11;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_CAGE:
begin
TPixel := True;
TCount := 150;
TWait := 3600;
end;

FISHSPOT_HARPOON:
begin
TPixel := True;
TCount := 160;
TWait := 3000;
end;
end;

MSI_Debug('Initializing vars');
WaitTime := GetSystemTime + 90000;
OldInvCount := InvCount;
MarkTime(InvTimer);

MSI_AddHeader('Starting Loop');
repeat
MSI_Debug('Randoms Check');
MSI_FindRandoms;
MSI_AntiBan(RandomRange(0, 3000), ANTI_BAN_CHANCE);

if InvFull then break;

// If no new fish in inv after 30 seconds, spot probably moved
MSI_Debug('InvTime check');
if (TimeFromMark(InvTimer) > MAX_FISH_WAIT) then
if (OldInvCount = InvCount) then
break
else begin
OldInvCount := InvCount;
MarkTime(InvTimer);
end;

MSI_Debug('TPixel check: ' + BoolToStr(TPixel));
if TPixel then
Fishing := MSI_FishPixels(TWait, TCount, SearchBox)
else
Fishing := MSI_FishGear(TColour, TTol, TCount, TWait, THue, TSat, SearchBox);

if not Fishing then break;

Wait(RandomRange(200, 500));

until(WaitTime > GetSystemTime)
MSI_CloseHeader('Ending Loop');

MSI_CloseHeader('WaitWhileFishing: Exiting');
end;

Just debug it >.> Look at where the debug ended and you'll know where it stopped.
MSI saves all the debugs to file… ;)

~RM


I was getting at this by the end of my frustration, but it seems to lead us into the PixelShift function, which means that maybe SRLs PixelShift is crashing it….?

I then updated MSI and then Fishing.simba wouldn't compile. So I cried.

Wizzup?

2010-09-01 11:05:06

From: Sir R. Magician
Guys, why the hell remove code… ?


const
MAX_FISH_WAIT = 30000;

{******************************************************************************}
{ Procedure MSI_WaitWhileFishing }
{ By: 3Garrett3 }
{ Date: 25 July 2010 }
{ Description: Waits while fishing }
{******************************************************************************}
procedure MSI_WaitWhileFishing;
var
OldInvCount, WaitTime, InvTimer, cts, i : Integer;
SearchBox : TBox;
script: TScript;
TColour, TTol, TCount, TWait : Integer;
THue, TSat : Extended;
TPixel, Fishing : Boolean;
begin

if InvFull then exit;

MSI_AddHeader('MSI_WaitWhileFishing');

Flag;
Wait(RandomRange(300, 450));

MSI_Debug('Detecting Side');
SearchBox := IntToBox(270, 148, 296, 180);
MakeCompass(MSI_DetectSide);

MSI_Debug('Getting Script Information');
script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
TPixel := False;

case (script.Objects[i]) of
FISHSPOT_NET:
begin
TPixel := True;
TCount := 150;
TWait := 3300;
end;

FISHSPOT_BAIT:
begin
TColour:= 727589;
TTol := 4;
THue := 0.17;
TSat := 0.65;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_LURE:
begin
TColour:= 859433;
TTol := 3;
THue := 0.19;
TSat := 1.11;
TCount := 50;
TWait := 4000;
end;

FISHSPOT_CAGE:
begin
TPixel := True;
TCount := 150;
TWait := 3600;
end;

FISHSPOT_HARPOON:
begin
TPixel := True;
TCount := 160;
TWait := 3000;
end;
end;

MSI_Debug('Initializing vars');
WaitTime := GetSystemTime + 90000;
OldInvCount := InvCount;
MarkTime(InvTimer);

MSI_AddHeader('Starting Loop');
repeat
MSI_Debug('Randoms Check');
MSI_FindRandoms;
MSI_AntiBan(RandomRange(0, 3000), ANTI_BAN_CHANCE);

if InvFull then break;

// If no new fish in inv after 30 seconds, spot probably moved
MSI_Debug('InvTime check');
if (TimeFromMark(InvTimer) > MAX_FISH_WAIT) then
if (OldInvCount = InvCount) then
break
else begin
OldInvCount := InvCount;
MarkTime(InvTimer);
end;

MSI_Debug('TPixel check: ' + BoolToStr(TPixel));
if TPixel then
Fishing := MSI_FishPixels(TWait, TCount, SearchBox)
else
Fishing := MSI_FishGear(TColour, TTol, TCount, TWait, THue, TSat, SearchBox);

if not Fishing then break;

Wait(RandomRange(200, 500));

until(WaitTime > GetSystemTime)
MSI_CloseHeader('Ending Loop');

MSI_CloseHeader('WaitWhileFishing: Exiting');
end;

Just debug it >.> Look at where the debug ended and you'll know where it stopped.
MSI saves all the debugs to file… ;)

~RM


If Simba crashes, then I don't think you can see where it stops. The only way then is to remove code until it doesn't crash, or to write debug data to files.

Sir R. M8gic1an

2010-09-01 11:28:33

From: Sir R. Magician


Just debug it >.> Look at where the debug ended and you'll know where it stopped.
MSI saves all the debugs to file… ;)

~RM


~RM

3Garrett3

2010-09-01 12:44:36

From: Sir R. Magician
~RM


I've run into another problem. I got it compiling. Something is messing up in the finding the water direction (helps narrow down fishing direction finding) so its not even getting to the part :P.

Tried adding a couple debugs, but it's not making too much progress yet

Wizzup?

2010-09-09 15:52:49

Any progress?

Coh3n

2010-09-09 22:11:36

From: Wizzup?
Any progress?

Yeah. :) As far as I know, fishing is up and running. As to how well it's running I'm not 100% sure, but running nonetheless.

Wizzup?

2010-09-10 17:36:42

But no clue as to the previous crashes?

Coh3n

2010-09-10 18:02:35

From: Wizzup?
But no clue as to the previous crashes?

No, I talked to Garrett and he has no idea what he did to prevent the crash. :unsure:

3Garrett3

2010-09-11 12:28:37

I just kinda picked it up one day and it wasn't crashing.. I have no idea what would have caused it..