diff --git a/utsCharCache.pas b/utsCharCache.pas index 542f116..9e12d76 100644 --- a/utsCharCache.pas +++ b/utsCharCache.pas @@ -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; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/utsFont.pas b/utsFont.pas index 213b656..8d9748a 100644 --- a/utsFont.pas +++ b/utsFont.pas @@ -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; diff --git a/utsOpenGLUtils.pas b/utsOpenGLUtils.pas index cd01c09..f3ac084 100644 --- a/utsOpenGLUtils.pas +++ b/utsOpenGLUtils.pas @@ -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; diff --git a/utsUtils.pas b/utsUtils.pas index 8594c9a..56d527c 100644 --- a/utsUtils.pas +++ b/utsUtils.pas @@ -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; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////