Jump to content
shadowrecon

Found Issue

Recommended Posts

In Map.Scar, you are creating a bmp and free it at the end but you have an exit statement between them. so if the exit state was true then the bmp would be left in the memory. eventually causing a error.

 

[scar]

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function FindMMDotsExOverlap(ColorDiffs: TIntegerArray): T2DPointArray;

Contributors: Wanted

Description: Finds all MMDots you specify i.e. cldWhiteDot etc. see Global.scar

This one uses overlapping checking, so it's twice as slow.

Date Created: December 8th, 2011. By Wanted. RS2 Build 688.

Last Modification: February 19th, 2012. By Wanted. RS2 Build 701.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function FindMMDotsExOverlap(ColorDiffs: TIntegerArray): T2DPointArray;

var

I, II, H, HH, Map, DC, Wi, He, C, O: Integer;

Offset: T2DPointArray;

TPA: TPointArray;

L: TIntegerArray;

B: Boolean;

begin

Result := [TPointArray([])];

HH := High(ColorDiffs);

SetLength(Result, HH + 1);

SetLength(L, HH + 1);

if (HH < 0 ) then

Exit;

Map := BitmapFromString(MMX2 - MMX1 + 4, MMY2 - MMY1 + 4, '');

CopyClientToBitmap(Map, MMX1 - 2, MMY1 - 2, MMX2 + 2, MMY2 + 2);

DC := GetClientCanvas.Handle;

SetTargetDC(GetBitmapDC(Map));

GetBitmapSize(Map, Wi, He);

FindColors(TPA, 65536, 3, 3, Wi - 3, He - 3);

FilterPointsDist(TPA, 0, MMRDe, (Wi / 2) - 2, (He / 2) - 2);

SetTargetDC(DC);

H := High(TPA);

if (H < 0) then

Exit;

Offset := [TPointArray([Point(-2, 0), Point(-1, 0)]), TPointArray([Point(0, -2), Point(0, -1)])];

for I := 0 to H do

for O := 0 to 1 do

begin

C := (FastGetPixel(Map, TPA.X + Offset[O][0].X, TPA.Y + Offset[O][0].Y) - FastGetPixel(Map, TPA.X + Offset[O][1].X, TPA.Y + Offset[O][1].Y));

B := False;

for II := 0 to HH do

if (C = ColorDiffs[iI]) then

begin

B := True;

Inc(L[iI]);

SetLength(Result[iI], L[iI]);

Result[iI][L[iI] - 1] := Point(TPA.X + MMX1 - 4, TPA.Y + MMY1 - 4);

Break;

end;

if (B) then

Break;

end;

FreeBitmap(Map);

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function FindMMDotsEx(ColorDiffs: TIntegerArray): T2DPointArray;

Contributors: Wanted

Description: Finds all MMDots you specify i.e. cldWhiteDot etc. see Global.scar

Date Created: December 8th, 2011. By Wanted. RS2 Build 688.

Last Modification: February 19th, 2012. By Wanted. RS2 Build 701.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function FindMMDotsEx(ColorDiffs: TIntegerArray): T2DPointArray;

var

I, II, H, HH, Map, DC, Wi, He, C: Integer;

L: TIntegerArray;

TPA: TPointArray;

begin

Result := [TPointArray([])];

HH := High(ColorDiffs);

SetLength(Result, HH + 1);

SetLength(L, HH + 1);

if (HH < 0 ) then

Exit;

Map := BitmapFromString(MMX2 - MMX1 + 4, MMY2 - MMY1 + 4, '');

CopyClientToBitmap(Map, MMX1 - 2, MMY1 - 2, MMX2 + 2, MMY2 + 2);

DC := GetClientCanvas.Handle;

SetTargetDC(GetBitmapDC(Map));

GetBitmapSize(Map, Wi, He);

FindColors(TPA, 65536, 3, 3, Wi - 3, He - 3);

FilterPointsDist(TPA, 0, MMRDe, (Wi / 2) - 2, (He / 2) - 2);

SetTargetDC(DC);

H := High(TPA);

if (H < 0) then

Exit; // <- But you could exit here.

for I := 0 to H do

begin

C := (FastGetPixel(Map, TPA.X - 2, TPA.Y) - FastGetPixel(Map, TPA.X - 1, TPA.Y));

for II := 0 to HH do

if (C = ColorDiffs[iI]) then

begin

Inc(L[iI]);

SetLength(Result[iI], L[iI]);

Result[iI][L[iI] - 1] := Point(TPA.X + MMX1 - 4, TPA.Y + MMY1 - 4);

Break;

end;

end;

FreeBitmap(Map); // <--- Free'ed here

end;

[/scar]

Link to comment
Share on other sites

The proper way of doing this would actually be

 

[scar]Map := BitmapFromString(MMX2 - MMX1 + 4, MMY2 - MMY1 + 4, '');

try

// All of the code

finally

FreeBitmap(Map);

end;[/scar]

 

Using try...finally, the finally section would be called when you exit the try section, even if you call Exit to get out of the function.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...