From 5c3a8740c15c5d2ac19525e19ac85dd97e66969a Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 31 Mar 2011 22:39:00 +0200 Subject: [PATCH] - Fixed more range violations (fixes #82) --- Client/ULightManager.pas | 16 ++++++++++------ UOLib/ULight.pas | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Client/ULightManager.pas b/Client/ULightManager.pas index 2a5d953..71789a3 100644 --- a/Client/ULightManager.pas +++ b/Client/ULightManager.pas @@ -21,7 +21,7 @@ * CDDL HEADER END * * - * Portions Copyright 2009 Andreas Schneider + * Portions Copyright 2011 Andreas Schneider *) unit ULightManager; @@ -31,7 +31,8 @@ interface uses Classes, SysUtils, Imaging, ImagingTypes, ImagingClasses, ImagingCanvases, - ImagingOpenGL, GL, GLu, GLext, fgl, ULandscape, UWorldItem, UCacheManager; + ImagingOpenGL, GL, GLu, GLext, fgl, ULandscape, UWorldItem, UCacheManager, + Math; type @@ -279,8 +280,10 @@ begin if tdfLightSource in tileData.Flags then lights.Add(blockInfo^.Item) else - tileMap[blockInfo^.Item.X - ALeft, blockInfo^.Item.Y - ATop] := - blockInfo^.Item; + x := blockInfo^.Item.X - ALeft; + y := blockInfo^.Item.Y - ATop; + if InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) then + tileMap[x, y] := blockInfo^.Item; end; end; @@ -288,8 +291,9 @@ begin begin x := lights[i].X + 1 - ALeft; y := lights[i].Y + 1 - ATop; - if (x = AWidth) or (y = AHeight) or (tileMap[x,y] = nil) or - (tileMap[x,y].Z < lights[i].Z + 5) then + if (x = AWidth) or (y = AHeight) or + (InRange(x, 0, AWidth - 1) and InRange(y, 0, AHeight - 1) and + ((tileMap[x,y] = nil) or (tileMap[x,y].Z < lights[i].Z + 5))) then FLightSources.Add(TLightSource.Create(Self, lights[i])); end; diff --git a/UOLib/ULight.pas b/UOLib/ULight.pas index dc14357..1a4ffc2 100644 --- a/UOLib/ULight.pas +++ b/UOLib/ULight.pas @@ -21,7 +21,7 @@ * CDDL HEADER END * * - * Portions Copyright 2009 Andreas Schneider + * Portions Copyright 2011 Andreas Schneider *) unit ULight; @@ -76,8 +76,8 @@ begin for y := 0 to Height - 1 do for x := 0 to Width - 1 do begin - buffer.Read(color, SizeOf(byte)); - color32.R := color * 8; + buffer.Read(color, SizeOf(Byte)); + color32.R := Byte(color * 8); color32.G := color32.R; color32.B := color32.R; if color > 0 then