ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Random Access Violation
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Homer

USA
70 Posts

Posted - Jan 26 2022 :  17:24:31  Show Profile  Reply
My app seems to run normally until closing the application. Then I sometimes get a non-specific Access Violation, but not always. This only occurs at shut-down, so I've enclosed everything in try/except blocks within the main form's onClose event. Nothing in that event throws an error.

Below is the JCL error log. It doesn't mention any of my code, but it does mention two events in iemview.pas. One is Destroy, the other is HideTextEditor. They appear to be in two different routines. Is it possible that Destroy occurs before the Hide?

<blockquote id="quote"><font size="2" face="Lato, Arial, Helvetica" id="quote"> <hr height="1" noshade id="quote">EAccessViolation: Access violation at address 00000000. Read of address 00000000
----------------------------
[004853F3] Controls.TWinControl.GetClientRect + $F
[0046C0B9] Forms.TCustomForm.GetClientRect + $7D
[0047C9B0] Controls.TControl.GetClientWidth + $C
[00469D21] Forms.TControlScrollBar.ControlSize + $71
[0046A48B] Forms.TControlScrollBar.Update + $E3
[00426FB1] Classes.TStream.SetPosition + $D
[0044180B] Graphics.TIcon.HandleNeeded + $1B
[0046A86E] Forms.TScrollingWinControl.UpdateScrollBars + $CE
[004417B9] Graphics.TIcon.GetHandle + $5
[0046F122] Forms.TCustomForm.GetIconHandle + $6
[0046E564] Forms.TCustomForm.CreateWnd + $24
[004818F2] Controls.TWinControl.CreateHandle + $16
[00485274] Controls.TWinControl.HandleNeeded + $1C
[00485281] Controls.TWinControl.GetHandle + $5
[00473653] Forms.GetTopMostWindows + $4B
[004736AA] Forms.TApplication.DoNormalizeTopMosts + $2A
[0047377E] Forms.TApplication.NormalizeTopMosts + $2
[00473F3F] Forms.TApplication.WndProc + $303
[00431050] Classes.StdWndProc + $14
[0042FF26] Classes.TThread.WaitFor + $3A
[007A38D8] iemview.TIECustomMView.HideTextEditor (Line 23400, "iemview.pas" + 19) + $18
[0078A80F] iemview.TIECustomMView.Destroy (Line 6008, "iemview.pas" + 19) + $9

[00480149] Controls.TWinControl.Destroy + $8D
[004873ED] Controls.TCustomControl.Destroy + $1D
[00480149] Controls.TWinControl.Destroy + $8D
[0046A564] Forms.TScrollingWinControl.Destroy + $28
[0046B579] Forms.TCustomForm.Destroy + $E1
[0043022F] Classes.TComponent.DestroyComponents + $47
[0046938A] Forms.DoneApplication + $32
[0040B036] SysUtils.DoExitProc + $26
[00405465] System.@Halt0 + $21
[00DA94A6] ABSIMG.ABSIMG (Line 45, "" + 23) + $20
[/quote]

xequte

38198 Posts

Posted - Jan 26 2022 :  21:05:43  Show Profile  Reply
Hi Homer

I cannot see anything unexpected there. Destroy calls HideTextEditor indirectly, and it should not matter in what order that occurs. The code also looks OK, and I did some test with the editor being used.

Does your application make any use of text editing (e.g. to rename fields of thumbnails)?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Jan 27 2022 :  02:03:00  Show Profile  Reply
No text editing via ImageEn. The only text editing is in database fields, not images.

As far as testing goes, I can run the app for hours, opening it, acquiring and deleting documents of various file types, and then closing it with no errors. It seems absolutely bug free. Then, out of the blue, an AV pops up when closing the app. When the AV pops up, I've done nothing different than I have all the many other times the app has been opened and closed. The JCL error log is always free from any mention of my code, as previously shown.

I've taken to freeing everything my app creates, including the imageEn components:

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  {$IFDEF UseCodeSite}
  CodeSite.TraceMethod('FormClose');
  {$ENDIF}
  try
    try
      if qImageList.State in [dsEdit, dsInsert] then qImageList.Post;
      if qCategories.state in [dsEdit, dsInsert] then qCategories.Post;
      if qAccountLookup.state in [dsEdit, dsInsert] then qAccountLookup.Post;
      if qLinkedPolicyNums.state in [dsEdit, dsInsert] then qLinkedPolicyNums.Post;
      if qTemp.state in [dsEdit, dsInsert] then qTemp.Post;

      if qImageList.active then qImageList.Close;
      if qCategories.active  then qCategories.Close;
      if qAccountLookup.active  then qAccountLookup.Close;
      if qLinkedPolicyNums.active then qLinkedPolicyNums.Close;
      if qTemp.active  then qTemp.Close;

      Application.ProcessMessages;
      { Record final size and position in Registry }
      if WindowState = wsMaximized then
        SetRegistryData(rrUser,'Options','Maximized',rdString,'1')
      else
      begin
        SetRegistryData(rrUser,'Options','Maximized',rdString,'0');
        SetRegistryData(rrUser,'Options','Top',rdInteger,top);
        SetRegistryData(rrUser,'Options','Left',rdInteger,Left);
        SetRegistryData(rrUser,'Options','Width',rdInteger,Width);
        SetRegistryData(rrUser,'Options','Height',rdInteger,Height);
      end;
      Application.ProcessMessages;
    finally
      FreeAndNil(slCaption);
      ImageEnView1.Free;
      ImageEnMView1.Free;
      iemvPageThumbs.Free;
      OleContainer1.Free;
      AcroPDF1.Free;

    end;
  except
    // silent
  end;
Go to Top of Page

xequte

38198 Posts

Posted - Jan 27 2022 :  15:02:03  Show Profile  Reply
Hi

Have you tried removing components to see if you can narrow it down?

What is the ABSIMG.ABSIMG in the debug log?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Jan 27 2022 :  20:33:01  Show Profile  Reply
I have not removed components because the problem is so intermittent and there are so many components, it would be almost impossible to tell what component it might be. On the other hand, all the components other than the upgraded ImageEn have been there for years.. I appreciate your suggestion, but I can't see how removing components that have been trouble free for many years would tell us anything. After all, we are talking abut Access Violations that occur only when the app is shut down.

So, yesterday, I did stuff in the OnClose event of the main form that really should not be needed. I tested every database table and query to see if their state was edit or insert then posted if they were. I tested to see if they might be open and closed then if they were. I added FreeAndNil for created forms and components, even ones that were freed in in-line Try/Finally blocks. I also added Try/Except blocks around everything done in the OnClose event. My thinking was to handle stuff that Delphi and Windows seemed to be occasionally missing. I've done quite a bit of testing since then, and so far, no AVs. But it's too soon to know because of the intermittent nature of these AVs. They only happen when closing the application, and rarely happen then. Bear in mind, this is a application that has been in production since ImageEn 2.1, and the only real change is the upgrade to 10.02. That was so I could add automatic sheet feeding. Almost everything else is fundamentally the same.

Because of its intermittent nature, I have actually thought the problem was solved at least five times because it didn't error during rigorous testing. Then, all of a sudden, out of the blue, it throws an AV on closing. And during that session everything worked as it should... everything.

I have powered down my development machine to see if I might have something going on in RAM. No change. It behaves the same way on three other computers (two without Delphi) so it's not hardware related. It happens on Windows 8.1 and 10, and on an 8.1 VM under Ubuntu. So it's not OS related.

I almost forgot to answer your question about the error log. ABSIMG.ABSIMG is the first entry in the log. The name of the .exe is ABSIMG.exe.
Go to Top of Page

xequte

38198 Posts

Posted - Jan 27 2022 :  23:52:48  Show Profile  Reply
Hi Homer

Yes, intermittent A/Vs are one of the worst to narrow down. If the only thing that has changed is the ImageEn version, then that does point to a bug or change in functionality in our code. Unfortunately we're not aware of any issues that might help you get closer to the offending bug/change.

Did the A/V that occurred after your changes happen in the destruction of any particular control? Or did it happen after all controls had been free and during the close of the final form?


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Jan 28 2022 :  01:22:23  Show Profile  Reply
It seems to occur in the main form's onClose event. The error message pops up immediately after the main form is gone. It's almost as if it occurs after the app closes. In thoery, by the time the AV is reported, everything should have already been destroyed.
Go to Top of Page

Homer

USA
70 Posts

Posted - Jan 28 2022 :  13:11:42  Show Profile  Reply
Better answer to your question about ABSIMG.ABSIMG, as well as a step I've taken to stop the AV message. Below is a copy of the Project Source for the ABSIMG app.

You'll notice the Error Log listing for ABSIMG.ABSIMG specifies line 45. Line 45 is the last line in the Project Source.

You will also note that all the executable lines are inside a Try/Except block. That's been there for several years and has worked great. It was put there because of an upgrade requiring Adobe Acrobat DC. When I put that in, I also re-stated the original E.Message. Notice that has now been commented out, making anything other than "Class Not Registered" a silent exception. My hope is that, since the AV occurs as (or after) the app closes, the message will not be displayed. At that point, even if an AV occurs, it shouldn't do any harm.

I welcome any thoughts on this.


program ABSIMG;
uses
  ContextMenuBugFix in 'ContextMenuBugFix.pas',
  sysutils,
  Windows,
  Forms,
  main in 'main.pas' {frmMain},
  Rotate in 'Rotate.pas' {fRotate},
  dlgXref in 'dlgXref.pas' {XrefDlg},
  Filter in 'Filter.pas',
  frmABSInterfaceU in 'frmABSInterfaceU.pas' {frmABSinterface},
  dlgCombineU in 'dlgCombineU.pas' {dlgCombineImages},
  LoadingFrm in 'LoadingFrm.pas' {frmLoading},
  dlgResizeImageUnit in 'dlgResizeImageUnit.pas' {dlgResizeImage},
  DBConnectUtils in 'DBConnectUtils.pas',
  dlgListEditorU in 'dlgListEditorU.pas' {dlgListEditor},
  dlgListLookupU in 'dlgListLookupU.pas' {dlgListLookup},
  OKCANCL1 in 'c:\program files (x86)\codegear\rad studio\5.0\ObjRepos\DelphiWin32\OKCANCL1.PAS' {OKBottomDlg},
  U_ExtdFileProperties in 'U_ExtdFileProperties.pas',
  MyDebugInfo in 'MyDebugInfo.pas';

begin
{$R *.res}
  try
    ReportMemoryLeaksOnShutdown := DebugHook <> 0;
    Application.Initialize;
    Application.Title := 'ABS Document Manager';
    Application.CreateForm(TfrmMain, frmMain);
    Application.Run;
  except
    on E : Exception do
    begin
      if (pos('class not',lowercase(E.Message)) <> 0) then
        MessageBox(Application.Handle,
          pChar('Adobe Acrobat Reader DC is required. Your version is out-of-date, '+
            'damaged or missing. YOU must install the latest version of Adobe Acrobat '+
            'Reader DC. Older versions are not compatible with ABS Document Manager.'),
          pChar('CLASS NOT REGISTERED'), MB_OK + MB_ICONERROR);
//      else
//        MessageBox(Application.Handle,
//          pChar(E.Message), pChar('Fatal Error'), MB_OK + MB_ICONERROR);
    end;
  end;

end.


Go to Top of Page

xequte

38198 Posts

Posted - Jan 28 2022 :  23:10:57  Show Profile  Reply
Hi

It would still be good to log your TearDown method to try and determine where the A/V occurs. But if the A/V is very sporadic it may be hard for you to justify the effort.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Jan 28 2022 :  23:34:33  Show Profile  Reply
I'm already using the Jedi (JCL) logging software. Are you talking about something more extrnsive?
Go to Top of Page

xequte

38198 Posts

Posted - Jan 28 2022 :  23:51:07  Show Profile  Reply
Yes, I mean something like:

// Free all components
Add2Log( 'Free RichEdit1' );
FreeAndNil( RichEdit1 );

Add2Log( 'Free ImageEnView1' );
FreeAndNil( ImageEnView1 );

Add2Log( 'Free ImageEnMView1' );
FreeAndNil( ImageEnMView1 );

etc.


If we can nail it down to one component, then we can debug its destructor...

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Homer

USA
70 Posts

Posted - Jan 29 2022 :  00:17:52  Show Profile  Reply
Okay, I'll look into it. Thanks for the ideas.
Go to Top of Page

fyaklin

USA
6 Posts

Posted - Feb 18 2022 :  09:55:20  Show Profile  Reply
I'm having a very similar issue. I have a form in a .dll that displays an image (TImageEnView). I'm not doing anything except LoadFromFile or LoadFromURL. The form displays normally, but when I exit the .dll, the main form closes. I never had this prior to 10.3.0. I can comment out the LoadFrom statements and it works normally. I'm having to replace the component with a TImage, but I would much rather use the TImageEnView.

Frederick J. Yaklin III
Go to Top of Page

xequte

38198 Posts

Posted - Feb 18 2022 :  22:27:43  Show Profile  Reply
Hi Frederick

Are you able to reproduce this in a simple demo?

What version were you using prior to 10.3.0?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: