diff --git a/UOLib/UGump.pas b/UOLib/UGump.pas index 5916366..308afe0 100644 --- a/UOLib/UGump.pas +++ b/UOLib/UGump.pas @@ -122,28 +122,35 @@ begin begin AData.Position := AIndex.Lookup; block := TMemoryStream.Create; - block.CopyFrom(AData, AIndex.Size); - block.Position := 0; - for i := 0 to AIndex.Height - 1 do - begin - block.Read(Offset, SizeOf(Integer)); - RowLookup[i] := Offset * 4; - end; - for iCurrentHeight := 0 to AIndex.Height - 1 do - begin - block.Position := RowLookup[iCurrentHeight]; - iCurrentWidth := 0; - while iCurrentWidth < AIndex.Width do + try + block.CopyFrom(AData, AIndex.Size); + block.Position := 0; + for i := 0 to AIndex.Height - 1 do begin - block.Read(Value, SizeOf(Word)); - block.Read(Run, SizeOf(Word)); - if Value > 0 then Value := Value or $8000; //Set alpha bit of non-black colors - for i := 0 to Run - 1 do - PWordArray(FGraphic.Bits + iCurrentHeight * AIndex.Width * 2)^[iCurrentWidth + i] := Value; - inc(iCurrentWidth, Run); + block.Read(Offset, SizeOf(Integer)); + RowLookup[i] := Offset * 4; end; + for iCurrentHeight := 0 to AIndex.Height - 1 do + begin + block.Position := RowLookup[iCurrentHeight]; + iCurrentWidth := 0; + while iCurrentWidth < AIndex.Width do + begin + if (block.Read(Value, SizeOf(Word)) < SizeOf(Word)) or + (block.Read(Run, SizeOf(Word)) < SizeOf(Word)) or (Run = 0) then + Break; + if Value > 0 then Value := Value or $8000; //Set alpha bit of non-black colors + for i := 0 to Run - 1 do + begin + if iCurrentWidth + i >= AIndex.Width then Break; + PWordArray(FGraphic.Bits + iCurrentHeight * AIndex.Width * 2)^[iCurrentWidth + i] := Value; + end; + inc(iCurrentWidth, Run); + end; + end; + finally + block.Free; end; - block.Free; end; FGraphic.Format := ifA8R8G8B8; end;