Skip to content

Commit

Permalink
Fix TObjectList freeing previous child when assigning by SetItem
Browse files Browse the repository at this point in the history
  • Loading branch information
michaliskambi committed Jul 11, 2017
1 parent 782179e commit 5e75869
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/audio/castlesoundengine.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1309,11 +1309,7 @@ procedure TSoundAllocator.ALContextClose;
if FAllocatedSources[I].Used then
FAllocatedSources[I].Release;
{ This will free FAllocatedSources[I], as FAllocatedSources owns children }
{ TODO: Generics.Collections bug, it doesn't free the children in this case,
since TList<T>.SetItem doesn't do notification about remove and addition.
Leave it non-nil, in this case it will be freed later by FreeAndNil(FAllocatedSources) anyway
FAllocatedSources[I] := nil;
}
end;

FreeAndNil(FAllocatedSources);
Expand Down Expand Up @@ -1445,11 +1441,7 @@ procedure TSoundAllocator.SetMaxAllocatedSources(const Value: Cardinal);
if FAllocatedSources[I].Used then
FAllocatedSources[I].Release;
{ This will free FAllocatedSources[I], as FAllocatedSources owns children }
{ TODO: Generics.Collections bug, it doesn't free the children in this case,
since TList<T>.SetItem doesn't do notification about remove and addition.
Leave it non-nil, in this case it will be freed later by SetCount anyway.
FAllocatedSources[I] := nil;
}
end;
FAllocatedSources.Count := MaxAllocatedSources;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ procedure TList<T>.SetItem(AIndex: SizeInt; const AValue: T);
if (AIndex < 0) or (AIndex >= Count) then
raise EArgumentOutOfRangeException.CreateRes(@SArgumentOutOfRange);

Notify(FItems[AIndex], cnRemoved);
FItems[AIndex] := AValue;
Notify(FItems[AIndex], cnAdded);
end;

function TList<T>.GetEnumerator: TEnumerator;
Expand Down

0 comments on commit 5e75869

Please sign in to comment.