Browse Source

fix bug with pen texture (lost storage, crash)

Unknown 6 years ago
parent
commit
d66dcc5ce2
2 changed files with 33 additions and 8 deletions
  1. 32 8
      lazpaintcontrols/lcvectororiginal.pas
  2. 1 0
      lazpaintcontrols/lcvectortextshapes.pas

+ 32 - 8
lazpaintcontrols/lcvectororiginal.pas

@@ -14,6 +14,7 @@ const
 
 
 type
 type
   TVectorOriginal = class;
   TVectorOriginal = class;
+  ArrayOfBGRABitmap = array of TBGRABitmap;
 
 
   TShapeChangeEvent = procedure(ASender: TObject; ABounds: TRectF) of object;
   TShapeChangeEvent = procedure(ASender: TObject; ABounds: TRectF) of object;
   TShapeEditingChangeEvent = procedure(ASender: TObject) of object;
   TShapeEditingChangeEvent = procedure(ASender: TObject) of object;
@@ -90,6 +91,7 @@ type
     function Duplicate: TVectorShape;
     function Duplicate: TVectorShape;
     class function StorageClassName: RawByteString; virtual; abstract;
     class function StorageClassName: RawByteString; virtual; abstract;
     function GetIsSlow({%H-}AMatrix: TAffineMatrix): boolean; virtual;
     function GetIsSlow({%H-}AMatrix: TAffineMatrix): boolean; virtual;
+    function GetUsedTextures: ArrayOfBGRABitmap;
     class function Fields: TVectorShapeFields; virtual;
     class function Fields: TVectorShapeFields; virtual;
     class function Usermodes: TVectorShapeUsermodes; virtual;
     class function Usermodes: TVectorShapeUsermodes; virtual;
     class function PreferPixelCentered: boolean; virtual;
     class function PreferPixelCentered: boolean; virtual;
@@ -471,6 +473,27 @@ begin
   result := false;
   result := false;
 end;
 end;
 
 
+function TVectorShape.GetUsedTextures: ArrayOfBGRABitmap;
+var
+  f: TVectorShapeFields;
+  nb: integer;
+begin
+  f := Fields;
+  setlength(result, 3);
+  nb := 0;
+  if (vsfBackFill in f) and (BackFill.FillType = vftTexture) then
+  begin
+    result[nb] := BackFill.Texture;
+    inc(nb);
+  end;
+  if (vsfPenFill in f) and (PenFill.FillType = vftTexture) then
+  begin
+    result[nb] := PenFill.Texture;
+    inc(nb);
+  end;
+  setlength(result, nb);
+end;
+
 class function TVectorShape.Fields: TVectorShapeFields;
 class function TVectorShape.Fields: TVectorShapeFields;
 begin
 begin
   result := [];
   result := [];
@@ -1130,18 +1153,15 @@ procedure TVectorOriginal.DiscardUnusedTextures;
 var
 var
   i, j: Integer;
   i, j: Integer;
   f: TVectorShapeFields;
   f: TVectorShapeFields;
-  tex: TBGRABitmap;
+  texs: array Of TBGRABitmap;
 begin
 begin
   for i := 0 to FTextureCount-1 do
   for i := 0 to FTextureCount-1 do
     FTextures[i].Counter:= 0;
     FTextures[i].Counter:= 0;
   for i := 0 to FShapes.Count-1 do
   for i := 0 to FShapes.Count-1 do
   begin
   begin
-    f:= FShapes[i].Fields;
-    if (vsfBackFill in f) and (FShapes[i].BackFill.FillType = vftTexture) then
-    begin
-      tex := FShapes[i].BackFill.Texture;
-      inc(FTextures[IndexOfTexture(GetTextureId(tex))].Counter);
-    end;
+    texs := FShapes[i].GetUsedTextures;
+    for j := 0 to high(texs) do
+      inc(FTextures[IndexOfTexture(GetTextureId(texs[j]))].Counter);
   end;
   end;
   for i := FTextureCount-1 downto 0 do
   for i := FTextureCount-1 downto 0 do
     if FTextures[i].Counter = 0 then
     if FTextures[i].Counter = 0 then
@@ -1157,6 +1177,9 @@ begin
 end;
 end;
 
 
 function TVectorOriginal.AddShape(AShape: TVectorShape): integer;
 function TVectorOriginal.AddShape(AShape: TVectorShape): integer;
+var
+  texs: ArrayOfBGRABitmap;
+  i: Integer;
 begin
 begin
   if AShape.Container <> self then
   if AShape.Container <> self then
   begin
   begin
@@ -1166,7 +1189,8 @@ begin
       raise exception.Create('Container mismatch');
       raise exception.Create('Container mismatch');
   end;
   end;
   result:= FShapes.Add(AShape);
   result:= FShapes.Add(AShape);
-  if (vsfBackFill in AShape.Fields) and (AShape.BackFill.FillType = vftTexture) then AddTexture(AShape.BackFill.Texture);
+  texs := AShape.GetUsedTextures;
+  for i := 0 to high(texs) do AddTexture(texs[i]);
   AShape.OnChange := @OnShapeChange;
   AShape.OnChange := @OnShapeChange;
   AShape.OnEditingChange := @OnShapeEditingChange;
   AShape.OnEditingChange := @OnShapeEditingChange;
   DiscardFrozenShapes;
   DiscardFrozenShapes;

+ 1 - 0
lazpaintcontrols/lcvectortextshapes.pas

@@ -728,6 +728,7 @@ begin
     tmpSource.Free;
     tmpSource.Free;
   end
   end
   else
   else
+  if PenFill.FillType <> vftNone then
   begin
   begin
     tmpSource := TBGRABitmap.Create(round(sourceRect.Width),ceil(sourceRect.Height),BGRABlack);
     tmpSource := TBGRABitmap.Create(round(sourceRect.Width),ceil(sourceRect.Height),BGRABlack);
     tl.DrawText(tmpSource,BGRAWhite);
     tl.DrawText(tmpSource,BGRAWhite);