Toolbar2000 icon indicating copy to clipboard operation
Toolbar2000 copied to clipboard

Finalization crash in TB2Acc.pas in TTBCustomAccObject.Destroy on Delphi 10.4.2 64bit

Open paveltresnak opened this issue 3 years ago • 2 comments

In finalization unit TB2Acc.pas is destroyed critical section LastAccObjectCritSect and after that is calling TTBCustomAccObject.Destroy (releasing interfaces) where is calling EnterCriticalSection(LastAccObjectCritSect). On 32bit are all AccObject released before destroing LastAccObjectCritSect.

paveltresnak avatar Apr 12 '21 06:04 paveltresnak

Isn't this a bug in Delphi x64 compiler?

zedxxx avatar Apr 12 '21 18:04 zedxxx

The patch from this issue may help: https://github.com/SilverpointDev/sptbxlib/issues/107

  TTBCustomAccObject = class(TTBBaseAccObject)
    ...
    class var AccessibilityFinalized: Boolean;
  end;

finalization
  DisconnectAccObjects;
  if NeedToUninitialize then
    CoUninitialize;
  if LastAccObject = nil then
    DeleteCriticalSection(LastAccObjectCritSect)
  else
    TTBCustomAccObject.AccessibilityFinalized  := True;

destructor TTBCustomAccObject.Destroy;
begin
  { Remove Self from linked list of objects }
  EnterCriticalSection(LastAccObjectCritSect);
  try
    if LastAccObject = Self then
      LastAccObject := FPrevious;
    if Assigned(FPrevious) then
      FPrevious.FNext := FNext;
    if Assigned(FNext) then
      FNext.FPrevious := FPrevious;
  finally
    LeaveCriticalSection(LastAccObjectCritSect);
  end;
  if AccessibilityFinalized and (LastAccObject = nil) then
    DeleteCriticalSection(LastAccObjectCritSect);
  inherited;
end;

zedxxx avatar Feb 27 '24 10:02 zedxxx