Jump to content

Memory error when close form


MoreWood

Recommended Posts

Hello, to search and display information about a product I have the following scenario:

- a form from where a form is opened with a preview camera and a barcode scanner component:

              FCamera: = TFCamera.Create (nil);
              FCamera.OnReadCode: = ReturnOkCodigo;
              TfgAnimationHelper.ShowForm (FCamera);


- in the form where the image is captured and scanned, I have an accept button that executes this CloseForm (true) code:

 

procedure TFCamera.CloseForm (OK: boolean);
begin
  if OK and Assigned (FOnReadCode) and (fgLabCode.Text <> '-') then FOnReadCode (fgLabCode.Text);

  TfgAnimationHelper.HideForm (Self, [TfgAnimationOption.ReleaseOnFinish]);
  FCamera: = nil;
end;


 The FOnReadCode event helps me to retrieve the code that has been read. This works fine executing like this on click button : CloseForm(true); , but if I use a configuration flag (TConfig.JO.B ['closeonread']) to close the form automatically when a barcode is identified, with this code, a memory error occurs (attach log file):

procedure TFCamera.fgBarcodeScanDetected (Sender: TObject;
  const ABarcodes: TArray <FGX.Scanner.Barcode.TfgBarcode>);
begin
 fgLabCode.Text: = ParseaCodigo (ABarcodes [0] .RawData); //. SubString (HOST_FULL.Length);
 if TConfig.JO.B ['closeonread'] then CloseForm (true) else
  begin
   TThread.ForceQueue (nil, procedure begin
    fgBarcodeScan.Active: = False;
   end);
  end;
end;

 

error_camera_scan_01.png

error_camera_scan_02.png

error_camera_preview.txt

Link to comment
Share on other sites

  • Administrators

Besides the bugfix, please fix the logic as follows:

procedure TFCamera.CloseForm (OK: boolean);
begin
  if FCamera = nil then
    Exit;

  if OK and Assigned (FOnReadCode) and (fgLabCode.Text <> '-') then FOnReadCode (fgLabCode.Text);

  TfgAnimationHelper.HideForm (Self, [TfgAnimationOption.ReleaseOnFinish]);
  FCamera: = nil;
end;

fgBarcodeScanDetected  and TfgAnimationHelper.HideForm both are called asynchronously. 

TfgAnimationHelper.HideForm with TfgAnimationOption.ReleaseOnFinish flag should not be allowed to call more than once, otherwise it will lead to double destruction of the form and memory corruption.

 

Link to comment
Share on other sites

8 часов назад, Viktor Akselrod сказал:

Besides the bugfix, please fix the logic as follows:


procedure TFCamera.CloseForm (OK: boolean);
begin
  if FCamera = nil then
    Exit;

  if OK and Assigned (FOnReadCode) and (fgLabCode.Text <> '-') then FOnReadCode (fgLabCode.Text);

  TfgAnimationHelper.HideForm (Self, [TfgAnimationOption.ReleaseOnFinish]);
  FCamera: = nil;
end;

fgBarcodeScanDetected  and TfgAnimationHelper.HideForm both are called asynchronously. 

TfgAnimationHelper.HideForm with TfgAnimationOption.ReleaseOnFinish flag should not be allowed to call more than once, otherwise it will lead to double destruction of the form and memory corruption.

 

  Hello, thanks for you reply. Closeform is called only once, either when detecting the barcode if the automatic closing flag is set or if the accept button of the form is pressed. Anyway, I add the verification that it tells me.

Link to comment
Share on other sites

  • Administrators

Hello.

TfgAnimationHelper.HideForm(Self, [TfgAnimationOption.ReleaseOnFinish]) - this call does not close immediately form.

first plays the animation, then enqueues the deletion and only then deletes the form.
during this time fgBarcodeScanDetected may fire several more times.

so it is important to prevent for double form destruction.

  • Like 1
Link to comment
Share on other sites

12 минут назад, Viktor Akselrod сказал:

Hello.

TfgAnimationHelper.HideForm(Self, [TfgAnimationOption.ReleaseOnFinish]) - this call does not close immediately form.

first plays the animation, then enqueues the deletion and only then deletes the form.
during this time fgBarcodeScanDetected may fire several more times.

so it is important to prevent for double form destruction.

Ok, I added the check if FCamera = nil then Exit, anyway the memory problem persist, I imagine it will solved with new release, thanks.

Link to comment
Share on other sites

  • 3 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...