You are not logged in.
Delphi 10.4
An application raises an exception on close.
---------------------------
Debugger Exception Notification
---------------------------
Project Project3.exe raised exception class EAccessViolation with message 'Access violation at address 5005FC74 in module 'rtl270.bpl'. Read of address 03592104'.
---------------------------
Break Continue Help
---------------------------
Library:
library Project4;
uses
mormot.core.variants;
{$R *.res}
begin
end.
Application
uses
mormot.core.variants;
procedure TForm.OnButtonClick(Sender: TObject);
begin
var h := LoadLibrary('Project4.dll');
FreeLibrary(h);
end;
Both application and dll compiled with checked Link with runtime packages with one package vcl
When I commented:
initialization
// InitializeUnit;
in mormot.core.variants application closes without any errors.
Last edited by radexpol (2021-09-30 07:33:45)
Offline
Even though that *seems* to solve your problem, disable portions of your code and watch when that error disappears. As many of us are using that unit as well any many more projects without that problem, I would believe that some part of your code is producing that hiccup.
Offline
@sakura, I have no more code, nothing to disable. That problem appears when using runtime packages.
Offline
@sakura, I have no more code, nothing to disable. That problem appears when using runtime packages.
Sorry, I missed that part with the runtime packages. Haven't tried that with mORMot 2, but design-time packages for the Delphi IDE never worked with mORMot 1 either. Slightly different, I know, but I believe that will be the case with run-time packages always, as mORMot is going deeply into the VMT and RTTI of the application. But let's see what Arnaud can tell :-)
Offline
If anyone else has this problem: the error occurs in freeing memory for the dynamic array: SynVariantTypes. This array is created in mormot.core.variants initialization. It contains interfaced objects.
By default, the array and its objects are released when the application is closed via RTL finalization.
However, when using it in dll, an AV exception is generated.
The hack solution is to explicitly free the array before reaching the RTL.Finalization stage.
procedure FinalizeSynVariantTypes;
begin
for var i: integer := 0 to length(SynVariantTypes) - 1 do
TObject(SynVariantTypes[i]).Free;
SetLength(SynVariantTypes, 0);
end;
For example, this procedure can be placed in the finalization part of another unit that uses mormot.core.variants (or mormot.core.log, which also includes this module)
Offline