plashenkov / Toolbar2000

TBX-ready version of Toolbar2000
Other
21 stars 10 forks source link

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

Open paveltresnak opened 3 years ago

paveltresnak commented 3 years ago

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.

zedxxx commented 3 years ago

Isn't this a bug in Delphi x64 compiler?

zedxxx commented 6 months ago

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;