From 13bbef79b15145b1cef6af598c6cdea131880b8f Mon Sep 17 00:00:00 2001 From: pyscripter Date: Tue, 16 Jan 2024 23:48:03 +0200 Subject: [PATCH] Fix https://github.com/TurboPack/SynEdit/issues/249 --- Source/SynDWrite.pas | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/SynDWrite.pas b/Source/SynDWrite.pas index d5561cb..41366dd 100644 --- a/Source/SynDWrite.pas +++ b/Source/SynDWrite.pas @@ -1433,6 +1433,8 @@ TSynDWrite = class class function DottedStrokeStyle: ID2D1StrokeStyle; static; class function GradientGutterBrush(StartColor, EndColor: TColor): ID2D1LinearGradientBrush; class procedure ResetRenderTarget; static; + // if SynEdit inside a DLL call Finalize before unloading the DLL (https://github.com/TurboPack/SynEdit/issues/249) + class procedure Finalize; end; TSynTextFormat = record @@ -1791,6 +1793,17 @@ class function TSynDWrite.DWriteFactory: IDWriteFactory; Result := SingletonDWriteFactory; end; +class procedure TSynDWrite.Finalize; +begin + FreeAndNil(TSynDWrite.FSolidBrushes); + TSynDWrite.SingletonDottedStrokeStyle := nil; + TSynDWrite.SingletonRenderTarget := nil; + TSynDWrite.SingletonGDIInterop := nil; + TSynDWrite.SingletonImagingFactory := nil; + TSynDWrite.SingletonPrintDocumentPackageTargetFactory := nil; + TSynDWrite.SingletonD2DFactory := nil; +end; + class function TSynDWrite.GDIInterop: IDWriteGdiInterop; var LocalGDIInterop: IDWriteGdiInterop; @@ -2209,5 +2222,5 @@ initialization clNoneF := D2D1ColorF(0, 0, 0, 0); finalization // Delphi 10.1 does not support class destructors - TSynDWrite.FSolidBrushes.Free; + TSynDWrite.Finalize; end.