mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 15:30:52 +02:00
fpvectorial: Fixes a crash caused by an uninitialized variable in the block search. Moved the block search to a separate function to make the code reusable and more clear.
git-svn-id: trunk@39632 -
This commit is contained in:
parent
c7d3e19290
commit
b6a578c647
@ -934,7 +934,7 @@ procedure TvDXFVectorialReader.ReadENTITIES(ATokens: TDXFTokens; AData: TvVector
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
CurToken: TDXFToken;
|
CurToken: TDXFToken;
|
||||||
lEntity: TvEntity;
|
lEntity: TvEntity; // only to help debugging
|
||||||
begin
|
begin
|
||||||
IsReadingPolyline := False;
|
IsReadingPolyline := False;
|
||||||
|
|
||||||
@ -1417,11 +1417,11 @@ var
|
|||||||
lName: string;
|
lName: string;
|
||||||
lBlock: TvBlock;
|
lBlock: TvBlock;
|
||||||
PosX, PosY, PosZ: Double;
|
PosX, PosY, PosZ: Double;
|
||||||
lCurEntity: TvEntity;
|
|
||||||
begin
|
begin
|
||||||
PosX := 0.0;
|
PosX := 0.0;
|
||||||
PosY := 0.0;
|
PosY := 0.0;
|
||||||
PosZ := 0.0;
|
PosZ := 0.0;
|
||||||
|
Result := nil;
|
||||||
|
|
||||||
for i := 0 to ATokens.Count - 1 do
|
for i := 0 to ATokens.Count - 1 do
|
||||||
begin
|
begin
|
||||||
@ -1443,15 +1443,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Find the block by its name
|
// Find the block by its name
|
||||||
for i := 0 to AData.GetEntitiesCount()-1 do
|
lBlock := TvBlock(AData.FindEntityWithNameAndType(lName, TvBlock));
|
||||||
begin
|
|
||||||
lCurEntity := AData.GetEntity(i);
|
|
||||||
if (lCurEntity is TvBlock) and (TvBlock(lCurEntity).Name = lName) then
|
|
||||||
begin
|
|
||||||
lBlock := TvBlock(lCurEntity);
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if lBlock = nil then Exit;
|
if lBlock = nil then Exit;
|
||||||
|
|
||||||
// write the data
|
// write the data
|
||||||
|
@ -211,6 +211,7 @@ type
|
|||||||
TvEntity = class
|
TvEntity = class
|
||||||
public
|
public
|
||||||
X, Y, Z: Double;
|
X, Y, Z: Double;
|
||||||
|
Name: string;
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
procedure Clear; virtual;
|
procedure Clear; virtual;
|
||||||
// in CalculateBoundingBox always remember to treat correctly the case of ADest=nil!!!
|
// in CalculateBoundingBox always remember to treat correctly the case of ADest=nil!!!
|
||||||
@ -228,6 +229,8 @@ type
|
|||||||
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual;
|
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; virtual;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TvEntityClass = class of TvEntity;
|
||||||
|
|
||||||
{ TvEntityWithPen }
|
{ TvEntityWithPen }
|
||||||
|
|
||||||
TvEntityWithPen = class(TvEntity)
|
TvEntityWithPen = class(TvEntity)
|
||||||
@ -526,7 +529,6 @@ type
|
|||||||
protected
|
protected
|
||||||
FElements: TFPList; // of TvEntity
|
FElements: TFPList; // of TvEntity
|
||||||
public
|
public
|
||||||
Name: string;
|
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
//
|
//
|
||||||
@ -547,7 +549,6 @@ type
|
|||||||
TvInsert = class(TvEntity)
|
TvInsert = class(TvEntity)
|
||||||
public
|
public
|
||||||
Block: TvBlock; // The block to be inserted
|
Block: TvBlock; // The block to be inserted
|
||||||
Name: string;
|
|
||||||
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0;
|
procedure Render(ADest: TFPCustomCanvas; ADestX: Integer = 0;
|
||||||
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
|
ADestY: Integer = 0; AMulX: Double = 1.0; AMulY: Double = 1.0); override;
|
||||||
end;
|
end;
|
||||||
@ -627,6 +628,7 @@ type
|
|||||||
function GetEntitiesCount: Integer;
|
function GetEntitiesCount: Integer;
|
||||||
function GetLastEntity(): TvEntity;
|
function GetLastEntity(): TvEntity;
|
||||||
function FindAndSelectEntity(Pos: TPoint): TvFindEntityResult;
|
function FindAndSelectEntity(Pos: TPoint): TvFindEntityResult;
|
||||||
|
function FindEntityWithNameAndType(AName: string; AType: TvEntityClass): TvEntity;
|
||||||
{ Data removing methods }
|
{ Data removing methods }
|
||||||
procedure Clear; virtual;
|
procedure Clear; virtual;
|
||||||
function DeleteEntity(AIndex: Cardinal): Boolean;
|
function DeleteEntity(AIndex: Cardinal): Boolean;
|
||||||
@ -2657,6 +2659,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TvVectorialPage.FindEntityWithNameAndType(AName: string;
|
||||||
|
AType: TvEntityClass): TvEntity;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
lCurEntity: TvEntity;
|
||||||
|
begin
|
||||||
|
Result := nil;
|
||||||
|
for i := 0 to GetEntitiesCount()-1 do
|
||||||
|
begin
|
||||||
|
lCurEntity := GetEntity(i);
|
||||||
|
if (lCurEntity is AType) and (lCurEntity.Name = AName) then
|
||||||
|
begin
|
||||||
|
Result := lCurEntity;
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TvVectorialPage.Clear;
|
procedure TvVectorialPage.Clear;
|
||||||
begin
|
begin
|
||||||
FEntities.ForEachCall(CallbackDeleteEntity, nil);
|
FEntities.ForEachCall(CallbackDeleteEntity, nil);
|
||||||
|
Loading…
Reference in New Issue
Block a user