Hi Nigel,
I think I now understand what happens.
If you fix the missing obj.Name = nil bug in RemoveVObjData and call ImageEnVect1.RemoveObject(0) repeatedly when fObjHeapCount>1 then fObjCount will become negative in RemoveVObject.
So I think there needs to be a flag that indicates that the object has been removed.
This seems to fix the problem, but I am not 100% sure:
Add a flag to TIEVObject:
TIEVObject = record
FreePending : Boolean;
...
end;
Then set the flag when clearing data:
procedure TImageEnVect.RemoveVObjData(var obj: TIEVObject);
begin
obj.FreePending := True;
if obj.BitmapIdx >= 0 then
begin
// free image data
FreeBitmap(obj.BitmapIdx);
obj.BitmapIdx := -1;
end;
// free name
if obj.Name <> nil then
begin
freemem(obj.Name);
obj.Name := nil;
end;
...
end;
Then check the flag in RemoveObject
procedure _RemoveObject(iObj: integer);
var
pobj: PIEVObject;
begin
pobj := GetObj(iObj);
if pobj^.FreePending then
begin
Raise EIEException.Create('Dead hobj handle '+IntToStr(iObj)) //or just ignore
end else
begin
UnSelObject(iObj);
RemoveVObjData(pobj^); // remove object data
RemoveVObject(iObj); // remove object
if iObj = fObjHeapCount - 1 then
// decrease the heap (but it doesn't realloc), because it is last object inserted
dec(fObjHeapCount);
DoVectorialChanged;
end;
end;
Best Regards
Eric