SRL Archive - SRL Bugs

FindFlag2


Wizzup?

2012-02-12 08:14:08

I believe there is an issue in FindFlag2. It changes the target temporarily - does some work and then frees the temporary target _before_ restoring the old target. This is not allowed as Simba will temporarily be without a target.

I'm not sure why this wasn't a problem before, but it caused exceptions on Linux with Lape.

Below a changed version where the temporary target is stored in 't', the old target is restored and then 't' is freed.

Please try this before committing as I've only tested it a bit. Although I'm pretty sure it's a safe change.

function FindFlag2(var X, Y: Integer): Boolean;
var
KMTarget, ITarget, I, Hi, Map, W, H, t: Integer;
TPA: TPointArray;
begin
Result := False;
Map := BitmapFromString(MMX2 - MMX1, MMY2 - MMY1, '');
CopyClientToBitmap(Map, MMX1, MMY1, MMX2, MMY2);
KMTarget := GetKeyMouseTarget;
ITarget := GetImageTarget;
SetTargetBitmap(Map);
GetBitmapSize(Map, W, H);
FindColors(TPA, 65536, 0, 0, W - 1, H -1);
FilterPointsDist(TPA, 0, 75.5, W div 2, H div 2);
Hi := Length(TPA);
for I := 0 to Hi - 1 do
if ((FastGetPixel(Map, TPA[I].X - 1, TPA[I].Y - 1) - FastGetPixel(Map, TPA[I].X, TPA[I].Y - 1)) = 6381921) then
begin
Result := True;
X := TPA[I].X + MMX1;
Y := TPA[I].Y + MMY1;
Break;
end;

t := GetImageTarget;
SetKeyMouseTarget(KMTarget);
SetImageTarget(ITarget);
FreeTarget(t);
FreeBitmap(Map);
end;

PS: It could also just use Freeze, couldn't it?

E: Also, GetColor() operates on the bitmap as well. So you could use that instead of FastGetPixel.

Coh3n

2012-02-15 20:06:32

Committed.

Narcle

2012-02-16 03:21:57

@Wizzup
Previous one I had it use freeze. Its about ~ twice as fast that way. But I tested this HELLA amounts the speed doesn't matter anymore for Flag other then when you want to call FlagPresent.

Idk, either way works - I prefer Freeze but general consensus was saying it gave problems… (only because it was committed wrong couple times, maybe even tampered with when it shouldn't of been)

Bonfield

2012-02-16 04:02:27

i think this is the first time i have heard of freeze being used, i know this is a little off topic but what are some good application for freeze?

weequ

2012-02-16 04:12:46

From: Bonfield
i think this is the first time i have heard of freeze being used, i know this is a little off topic but what are some good application for freeze?
For example Flag is moving quite rapidly and FindFlag2 compares the nearby pixels so it would sometimes fail if the flag has moved during the process.