| @@ -73,7 +73,7 @@ type | |||||
| function GetChars(const aKey: TtsFont): TtsChars; | function GetChars(const aKey: TtsFont): TtsChars; | ||||
| function Find(const aMin, aMax: Integer; const aKey: TtsFont; out aIndex: Integer): Integer; | function Find(const aMin, aMax: Integer; const aKey: TtsFont; out aIndex: Integer): Integer; | ||||
| protected | protected | ||||
| procedure DelSlave(const aSlave: TtsRefManager); override; | |||||
| function DelSlave(const aSlave: TtsRefManager): Boolean; override; | |||||
| public | public | ||||
| property Chars[const aKey: TtsFont]: TtsChars read GetChars; | property Chars[const aKey: TtsFont]: TtsChars read GetChars; | ||||
| @@ -459,19 +459,22 @@ begin | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TtsCharCache.DelSlave(const aSlave: TtsRefManager); | |||||
| function TtsCharCache.DelSlave(const aSlave: TtsRefManager): Boolean; | |||||
| var | var | ||||
| f: TtsFont; | |||||
| pos, index: Integer; | pos, index: Integer; | ||||
| p: PtsCharCacheItem; | p: PtsCharCacheItem; | ||||
| begin | 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 | if (pos >= 0) then begin | ||||
| p := PtsCharCacheItem(fItems[pos]); | p := PtsCharCacheItem(fItems[pos]); | ||||
| fItems.Delete(pos); | fItems.Delete(pos); | ||||
| FreeAndNil(p^.val); | FreeAndNil(p^.val); | ||||
| Dispose(p); | Dispose(p); | ||||
| end; | end; | ||||
| inherited DelSlave(aSlave); | |||||
| result := inherited DelSlave(aSlave); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -482,10 +485,8 @@ var | |||||
| begin | begin | ||||
| for i := 0 to fItems.Count-1 do begin | for i := 0 to fItems.Count-1 do begin | ||||
| p := PtsCharCacheItem(fItems[i]); | p := PtsCharCacheItem(fItems[i]); | ||||
| FreeAndNil(p^.val); | |||||
| Dispose(p); | |||||
| p^.key.DelMaster(self); | |||||
| end; | end; | ||||
| fItems.Clear; | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -22,7 +22,7 @@ type | |||||
| fCharSpacing: Integer; | fCharSpacing: Integer; | ||||
| fLineSpacing: Single; | fLineSpacing: Single; | ||||
| protected | 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 | public | ||||
| property Names: TtsFontNames read fNames; | property Names: TtsFontNames read fNames; | ||||
| property Metric: TtsFontMetric read fMetric; | property Metric: TtsFontMetric read fMetric; | ||||
| @@ -42,9 +42,9 @@ implementation | |||||
| /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TtsFont////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //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 | begin | ||||
| inherited Create(aMaster); | |||||
| inherited Create(aCreator); | |||||
| fMetric := aMetric; | fMetric := aMetric; | ||||
| fNames := aNames; | fNames := aNames; | ||||
| end; | end; | ||||
| @@ -149,6 +149,10 @@ begin | |||||
| if Assigned(aTexture^.Next) then | if Assigned(aTexture^.Next) then | ||||
| aTexture^.Next^.Prev := aTexture^.Prev; | aTexture^.Next^.Prev := aTexture^.Prev; | ||||
| Dispose(aTexture); | Dispose(aTexture); | ||||
| if (fFirstTexture = aTexture) then begin | |||||
| fFirstTexture := nil; | |||||
| fLastTexture := nil; | |||||
| end; | |||||
| aTexture := nil; | aTexture := nil; | ||||
| end; | end; | ||||
| @@ -325,18 +329,14 @@ begin | |||||
| if (tex^.ID = ref.TextureID) then begin | if (tex^.ID = ref.TextureID) then begin | ||||
| if not RemoveFromTree(tex^.Usage, 0, 0, tex^.Size, tex^.Size) then | if not RemoveFromTree(tex^.Usage, 0, 0, tex^.Size, tex^.Size) then | ||||
| raise EtsRendererOpenGL.Create('unable to remove render ref from texture'); | 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); | FreeTexture(tex); | ||||
| end; | |||||
| tex := nil; | tex := nil; | ||||
| end else | end else | ||||
| tex := tex^.Next; | tex := tex^.Next; | ||||
| end; | end; | ||||
| finally | finally | ||||
| if Assigned(ref) then | |||||
| ref.Free; | |||||
| FreeAndNil(ref); | |||||
| end; | end; | ||||
| end; | end; | ||||
| @@ -14,11 +14,11 @@ type | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TtsRefManager = class(TObject) | TtsRefManager = class(TObject) | ||||
| private | 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 | protected | ||||
| procedure AddSlave(const aSlave: TtsRefManager); virtual; | procedure AddSlave(const aSlave: TtsRefManager); virtual; | ||||
| procedure DelSlave(const aSlave: TtsRefManager); virtual; | |||||
| function DelSlave(const aSlave: TtsRefManager): Boolean; virtual; | |||||
| public | public | ||||
| constructor Create(const aMaster: TtsRefManager); | constructor Create(const aMaster: TtsRefManager); | ||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| @@ -126,10 +126,11 @@ begin | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TtsRefManager.DelSlave(const aSlave: TtsRefManager); | |||||
| function TtsRefManager.DelSlave(const aSlave: TtsRefManager): Boolean; | |||||
| begin | begin | ||||
| result := false; | |||||
| if Assigned(fSlaveRefs) then | if Assigned(fSlaveRefs) then | ||||
| fSlaveRefs.Remove(aSlave); | |||||
| result := (fSlaveRefs.Remove(aSlave) >= 0); | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||