- Fixed more range violations (fixes #82)

This commit is contained in:
Andreas Schneider 2011-03-31 22:39:00 +02:00
parent abe62e13b8
commit 5c3a8740c1
2 changed files with 13 additions and 9 deletions

View File

@ -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;

View File

@ -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