Recent

Author Topic: Where does "External Access Violation" come from mostly?  (Read 1088 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1436
Where does "External Access Violation" come from mostly?
« on: June 05, 2024, 07:11:54 am »
I had recently encountered it, and solved it, and encounter it again in different setting. What's the likely cause? My brain is cluttered (as always) and cannot focus any more.

Thaddy

  • Hero Member
  • *****
  • Posts: 15531
  • Censorship about opinions does not belong here.
Re: Where does "External Access Violation" come from mostly?
« Reply #1 on: June 05, 2024, 07:51:58 am »
Usually it means that you asked a shared library to do something stupid, E.g. providing a parameter as an empty pchar without allocating memory for it, buffer overruns, mixing up by reference and by value, wrong calling convention, trying to pass pascal strings to a library written in another language, misaligned records, etc. It is usually not the shared library that is at fault, but the way the programmer tries to use it. This may also occur in OS provided shared libraries, like Windows dll's. Garbage in, garbage out.
« Last Edit: June 05, 2024, 07:59:39 am by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7503
Re: Where does "External Access Violation" come from mostly?
« Reply #2 on: June 05, 2024, 07:54:44 am »
Bad pointer, trapped by the (hardware) and operating system and reported to you rather than crashing the computer.

Complicated in the case of Object Pascal by the fact that strings, dynamic arrays etc. are accessed by pointers which have been initialised (and hopefully tidied up) implicitly, while (instances) of classes start off as a pointer containing rubbish which must be initialised manually (a .Create()) and then freed manually (Free) after which they must no longer be used (that's where FreeAndNil() is useful).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1497
    • http://www.cdbc.dk
Re: Where does "External Access Violation" come from mostly?
« Reply #3 on: June 05, 2024, 07:59:35 am »
Hi
edit: Thaddy & Mark beat me to it...
The first obvious one would be: do you use libraries?!?
The second one would be: do you use external threads?!?
The third one would be: OS-api calls
OFC, these 3 can be 1 os-api-call in a library that creates a thread  :D
...and AVs are mostly to do with accessing memory/parts, that you don't have rights to, haven't created or have already free'd.
Regards Benny
« Last Edit: June 05, 2024, 08:03:42 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

egsuh

  • Hero Member
  • *****
  • Posts: 1436
Re: Where does "External Access Violation" come from mostly?
« Reply #4 on: June 05, 2024, 08:29:55 am »
I do not use libraries, self-created threads, ...

I use RTTI controls. Possibly this might be related.
Interesting thing is that when I close the form altogether there are no problem. Problem happens when I try to clear internal data only and reset. 
Even with the exception message, I can continue to run the application. Anyway I'll look into this more.

cdbc

  • Hero Member
  • *****
  • Posts: 1497
    • http://www.cdbc.dk
Re: Where does "External Access Violation" come from mostly?
« Reply #5 on: June 05, 2024, 08:59:01 am »
Hi
Come to think of it...
I once had a run-in with the memory-manager and managed types; If you have managed types(strings, arrays & interfaces) and suddenly cut off the connection to the memory-manager in charge, you'll hear that kind of screamin' from your machine, when the compiler tries to free memory  :D  >:(  :D
It's kinda fun, just you try and remove the memory-manager in a running application... 8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

egsuh

  • Hero Member
  • *****
  • Posts: 1436
Re: Where does "External Access Violation" come from mostly?
« Reply #6 on: June 05, 2024, 09:09:32 am »
Not easy to do anything...

Code: Pascal  [Select][+][-]
  1. procedure TCustomGrid.WndProc(var TheMessage: TLMessage);
  2. begin
  3.   {$ifdef GridTraceMsg}
  4.   TransMsg('GRID: ', TheMessage);
  5.   {$endif}
  6.   case TheMessage.Msg of
  7.     LM_HSCROLL, LM_VSCROLL:
  8.       if csDesigning in ComponentState then
  9.         exit;
  10.     {$IFDEF MSWINDOWS}
  11.     // Ignore LM_SIZE while another sizing is being processed.
  12.     // Windows sends WM_SIZE when showing/hiding scrollbars.
  13.     // Scrollbars can be shown/hidden when processing DoOnChangeBounds.
  14.     LM_SIZE:
  15.       if gfUpdatingSize in FGridFlags then
  16.         exit;
  17.     {$ENDIF}
  18.   end;
  19.   inherited WndProc(TheMessage);
  20.   if not (FGridState in [gsColMoving, gsRowMoving]) then //For sure if MouseUp event is lost
  21.     FreeAndNil(FScroller);        // <===================  the error comes from here.
  22. end;
  23.  

MarkMLl

  • Hero Member
  • *****
  • Posts: 7503
Re: Where does "External Access Violation" come from mostly?
« Reply #7 on: June 05, 2024, 09:22:02 am »
Expect a problem if fScroller is only one of several references (pointers) to the instance being freed.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1497
    • http://www.cdbc.dk
Re: Where does "External Access Violation" come from mostly?
« Reply #8 on: June 05, 2024, 09:59:40 am »
Hi
Quote
  if not (FGridState in [gsColMoving, gsRowMoving]) then //For sure if MouseUp event is lost
    FreeAndNil(FScroller);        // <===================  the error comes from here.
Is this your doing or Lazarus' ?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

egsuh

  • Hero Member
  • *****
  • Posts: 1436
Re: Where does "External Access Violation" come from mostly?
« Reply #9 on: June 05, 2024, 10:15:12 am »
Hi
Quote
  if not (FGridState in [gsColMoving, gsRowMoving]) then //For sure if MouseUp event is lost
    FreeAndNil(FScroller);        // <===================  the error comes from here.
Is this your doing or Lazarus' ?!?
Regards Benny

This is Lazarus. unit Grids.

cdbc

  • Hero Member
  • *****
  • Posts: 1497
    • http://www.cdbc.dk
Re: Where does "External Access Violation" come from mostly?
« Reply #10 on: June 05, 2024, 10:54:10 am »
Hi
Then look further up/before in /your/ code(since you're the only one with the problem, it's safe to assume it's in your code, not lazarus').
Regards benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

egsuh

  • Hero Member
  • *****
  • Posts: 1436
Re: Where does "External Access Violation" come from mostly?
« Reply #11 on: June 05, 2024, 11:48:41 am »
Hi
Then look further up/before in /your/ code(since you're the only one with the problem, it's safe to assume it's in your code, not lazarus').
Regards benny

Yes, I agree. But it's really interesting, as the error occurs ONLY WHEN the TVALUELISTEDITOR is FOCUSED (and I try to close the internal classes). When the focus is moved away by clicking other control, then no problem. I'm trying to move the focus away in program, but not successful yet. I have employed various methods.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7503
Re: Where does "External Access Violation" come from mostly?
« Reply #12 on: June 05, 2024, 12:02:08 pm »
Yes, I agree. But it's really interesting, as the error occurs ONLY WHEN the TVALUELISTEDITOR is FOCUSED (and I try to close the internal classes). When the focus is moved away by clicking other control, then no problem. I'm trying to move the focus away in program, but not successful yet. I have employed various methods.

Only when the control is focused will anything be interested in the state of the scrollbar.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018