Browse Source

* fixed bug in OpenGL texture manager

master
Bergmann89 8 years ago
parent
commit
acf68a7041
4 changed files with 23 additions and 21 deletions
  1. +8
    -7
      utsCharCache.pas
  2. +3
    -3
      utsFont.pas
  3. +6
    -6
      utsOpenGLUtils.pas
  4. +6
    -5
      utsUtils.pas

+ 8
- 7
utsCharCache.pas View File

@@ -73,7 +73,7 @@ type
function GetChars(const aKey: TtsFont): TtsChars;
function Find(const aMin, aMax: Integer; const aKey: TtsFont; out aIndex: Integer): Integer;
protected
procedure DelSlave(const aSlave: TtsRefManager); override;
function DelSlave(const aSlave: TtsRefManager): Boolean; override;
public
property Chars[const aKey: TtsFont]: TtsChars read GetChars;

@@ -459,19 +459,22 @@ begin
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TtsCharCache.DelSlave(const aSlave: TtsRefManager);
function TtsCharCache.DelSlave(const aSlave: TtsRefManager): Boolean;
var
f: TtsFont;
pos, index: Integer;
p: PtsCharCacheItem;
begin
pos := Find(0, fItems.Count-1, aSlave as TtsFont, index);
f := (aSlave as TtsFont);
f.DelMaster(self);
pos := Find(0, fItems.Count-1, f, index);
if (pos >= 0) then begin
p := PtsCharCacheItem(fItems[pos]);
fItems.Delete(pos);
FreeAndNil(p^.val);
Dispose(p);
end;
inherited DelSlave(aSlave);
result := inherited DelSlave(aSlave);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -482,10 +485,8 @@ var
begin
for i := 0 to fItems.Count-1 do begin
p := PtsCharCacheItem(fItems[i]);
FreeAndNil(p^.val);
Dispose(p);
p^.key.DelMaster(self);
end;
fItems.Clear;
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


+ 3
- 3
utsFont.pas View File

@@ -22,7 +22,7 @@ type
fCharSpacing: Integer;
fLineSpacing: Single;
protected
{%H-}constructor Create(const aMaster: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames);
{%H-}constructor Create(const aCreator: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames);
public
property Names: TtsFontNames read fNames;
property Metric: TtsFontMetric read fMetric;
@@ -42,9 +42,9 @@ implementation
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TtsFont//////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TtsFont.Create(const aMaster: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames);
constructor TtsFont.Create(const aCreator: TtsRefManager; const aMetric: TtsFontMetric; const aNames: TtsFontNames);
begin
inherited Create(aMaster);
inherited Create(aCreator);
fMetric := aMetric;
fNames := aNames;
end;


+ 6
- 6
utsOpenGLUtils.pas View File

@@ -149,6 +149,10 @@ begin
if Assigned(aTexture^.Next) then
aTexture^.Next^.Prev := aTexture^.Prev;
Dispose(aTexture);
if (fFirstTexture = aTexture) then begin
fFirstTexture := nil;
fLastTexture := nil;
end;
aTexture := nil;
end;

@@ -325,18 +329,14 @@ begin
if (tex^.ID = ref.TextureID) then begin
if not RemoveFromTree(tex^.Usage, 0, 0, tex^.Size, tex^.Size) then
raise EtsRendererOpenGL.Create('unable to remove render ref from texture');
if IsEmtpy(tex^.Usage) then begin
if (tex = fFirstTexture) then
fFirstTexture := nil;
if IsEmtpy(tex^.Usage) then
FreeTexture(tex);
end;
tex := nil;
end else
tex := tex^.Next;
end;
finally
if Assigned(ref) then
ref.Free;
FreeAndNil(ref);
end;
end;



+ 6
- 5
utsUtils.pas View File

@@ -14,11 +14,11 @@ type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TtsRefManager = class(TObject)
private
fMasterRef: TtsRefManager;
fSlaveRefs: TObjectList;
fMasterRef: TtsRefManager; // master of this object (master will destroy this object)
fSlaveRefs: TObjectList; // slaves of this object (will destroy all slaves when this objects is destroyed)
protected
procedure AddSlave(const aSlave: TtsRefManager); virtual;
procedure DelSlave(const aSlave: TtsRefManager); virtual;
function DelSlave(const aSlave: TtsRefManager): Boolean; virtual;
public
constructor Create(const aMaster: TtsRefManager);
destructor Destroy; override;
@@ -126,10 +126,11 @@ begin
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TtsRefManager.DelSlave(const aSlave: TtsRefManager);
function TtsRefManager.DelSlave(const aSlave: TtsRefManager): Boolean;
begin
result := false;
if Assigned(fSlaveRefs) then
fSlaveRefs.Remove(aSlave);
result := (fSlaveRefs.Remove(aSlave) >= 0);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Loading…
Cancel
Save