Recent

Author Topic: [SOLVED] IDE - How to debug "Read Error - Access Violation" on closing a Form?  (Read 360 times)

Hansaplast

  • Hero Member
  • *****
  • Posts: 762
  • Tweaking4All.com
    • Tweaking4All
I'm running Lazarus from trunk (Lazarus 4.99 (rev main_4_99-2821-gcab4db5c42) FPC 3.3.1 x86_64-darwin-cocoa).

When closing one of the forms of my project I get a "Read Error" - "Access Violation" message, which also happend when I select "View source(lfm)".
I've narrowed it down to one specific form, so I suspect the LFM may be corrupted or something like that.

What can I do to debug this?
I've tried starting Lazarus straight from Terminal so I could hopefully see error messages (log file would have been great - not sure how to enable that), but they didn't show me anything helpful.

This is the error I see, from which I can only conclude that it failed to destroy a component:

Code: Pascal  [Select][+][-]
  1. Error: (lazarus) [LoadAncestorDependencyHidden] LoadComponentDependencyHidden failed ClsUnitInfo=/Users/hans/LazarusProjects/TestProject/mainunit.lfm ClsName="TForm1"
  2. LoadLFM LoadAncestorDependencyHidden failed for /Users/hans/LazarusProjects/TestProject/mainunit.lfm
  3. FoldState loading removed data for foldtype: 0
  4. [TJITComponentList.DestroyJITComponent] ERROR destroying component Error: Access violation
  5.   Stack trace:
  6.   $00000001044CF092
  7.   $000000010426BDD7
  8.   $00000001044C7609
  9.   $00000001044B590A
  10.   $0000000104367C06
  11.   $00000001044C765A
  12.   $00000001044B590A
  13.   $00000001044C9F9E
  14.   $00000001042D04AE
  15.   $00000001042D1B39
  16.   $000000010426BDD7
  17.   $00000001049DE338
  18.   $00000001049FF721
  19.   $00000001049F0EB4
  20.   $0000000104D3BCEA
  21.   $0000000104327C0E
  22.   $00000001042E063A
  23. TCustomFormEditor.JITListException List.CurReadStreamClass=nil nil

Note: I did a debug build of the IDE as well, and there the error keeps going for almost a minute with stack trace outputs that appear not very helpful.
Note: disabled and enabled hiding non-visual components, this didn't make a difference either (just to exclude that as an issue).

Any tips, tricks or insight would be most welcome.
« Last Edit: November 21, 2025, 01:48:14 pm by Hansaplast »

Hansaplast

  • Hero Member
  • *****
  • Posts: 762
  • Tweaking4All.com
    • Tweaking4All
Re: IDE - How to debug "Read Error - Access Violation" on closing a Form?
« Reply #1 on: November 21, 2025, 01:47:39 pm »
Still not sure what the best way is, but I started with this approach, maybe its helpful to others.

I made a copy of my project and kept removing controls until I narrowed the error down to a handful of controls.
Each time saving the changes, view LFM and see if the error kept coming back.

I noticed a few controls made anchoring go bonkers (insane heights for example).
In the end I just removed the handful remaining controls and re-created them.

Problem solved.


While recreating the controls I noticed the error being triggered by using anchors.

Not sure if this is even possible, but maybe the devs (grateful for their work!) could include the name of a control when such an exception occurs somewhere in the future.
« Last Edit: November 21, 2025, 01:50:58 pm by Hansaplast »

Thaddy

  • Hero Member
  • *****
  • Posts: 18703
  • To Europe: simply sell USA bonds: dollar collapses
Ask yourself: how would I debug a file that is mutilated?
In what way is it mutilated?
Has the mutilation anyhing to do with the language?
Can FPC detect hardware failures?
Now, you are usually on Apple hardware which is not known for sudden defects, but first check the storage medium.

A read error is the worst to debug because it indicates that the file is not valid.
You will get the same error or garbage if you try to open it with some other program. Did you check that?

You basically "fixed" this because of your backups.... That is not a fix.
« Last Edit: November 21, 2025, 02:17:58 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Hansaplast

  • Hero Member
  • *****
  • Posts: 762
  • Tweaking4All.com
    • Tweaking4All
I think you misunderstood the error and my fix.
This was not a file corruption as you suggest (which could happen of course) due to hardware failure, but rather through incorrect info in the LFM, or an invalid control or property, or control anchoring that didn't work as it should.

As mentioned: I was able to reproduce the error by simply removing and re-adding the controls and setting the anchors (the latter showing the error again).

I didn't need a backup - I just made a backup (after the error) so I could eliminate controls from the form until the error disappeared without ruining my project.
My project saved just fine, even with the error - and the files did get saved just fine as well.
Opening the LFM with a text editor showed a clean text file, no corruption there (which I had tried, hoping to find the faulty line).
« Last Edit: November 21, 2025, 02:45:22 pm by Hansaplast »

Thaddy

  • Hero Member
  • *****
  • Posts: 18703
  • To Europe: simply sell USA bonds: dollar collapses
Curious: can you send me a copy of a program that fails in that way? Can be private. Never seen it.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Hansaplast

  • Hero Member
  • *****
  • Posts: 762
  • Tweaking4All.com
    • Tweaking4All
It's pretty big - let me see if I can make a project that reproduces this (may take a day or two). 😊
Especially since there may be a bug in anchoring (or related to anchoring).
I have had a few occasions where removing a control would trigger an error where (for example) height of an attached control would go out of range.

 

TinyPortal © 2005-2018