Recent

Author Topic: Possible cause of error  (Read 761 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1729
Possible cause of error
« on: October 21, 2025, 07:47:17 am »
My application works fine, regarding my own operations. But when I try to close the application, Access Violation error occurs at following point. Following codes are from WinProc32.pp.

What could be possible reason? May I have cleard "menus" myself?
I understand some error in my own codes have caused this problem. But when I set heaptrc then no problem --- as this error happens only after I execute a specific procedure (rather complex).

Code: Pascal  [Select][+][-]
  1. procedure DoInitialization;
  2. begin
  3.   DefaultWindowInfo := Default(TWin32WindowInfo);
  4.   DefaultWindowInfo.DrawItemIndex := -1;
  5.   WindowInfoAtom := Windows.GlobalAddAtom('WindowInfo');
  6.   ChangedMenus := TFPList.Create;
  7.   if WindowsVersion = wvUnknown then
  8.     UpdateWindowsVersion;
  9. end;
  10.  
  11. {$IFDEF ASSERT_IS_ON}
  12.   {$UNDEF ASSERT_IS_ON}
  13.   {$C-}
  14. {$ENDIF}
  15.  
  16. initialization
  17.   DoInitialization;
  18.  
  19. finalization
  20.   Windows.GlobalDeleteAtom(WindowInfoAtom);
  21.   WindowInfoAtom := 0;
  22.   ChangedMenus.Free;  // <=========== error at here
  23.   FreeAndNil(PopupOwnersList);
                                                         
« Last Edit: October 21, 2025, 07:51:10 am by egsuh »

cdbc

  • Hero Member
  • *****
  • Posts: 2557
    • http://www.cdbc.dk
Re: Possible cause of error
« Reply #1 on: October 21, 2025, 08:11:53 am »
Hi
I had this once, with Qt, a mysterious error deep inside the Qt widgetset code, yours looks a lot like that...  %)
It took me a very long time to hunt the bastard down: It was a /double-free/ buried deep inside my own code, that manifested itself that way  ...go figure  >:(
Happy Hunting matey...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Khrys

  • Sr. Member
  • ****
  • Posts: 376
Re: Possible cause of error
« Reply #2 on: October 21, 2025, 09:50:14 am »
Take @cbdc's cautionary tale by heart and check your own code. Use Valgrind or better yet Address Sanitizer (requires recompilation of FPC on Linux) before combing through library code.

When your own code invokes undefined behavior, anything can happen. The only correct way to proceed is to get rid of said UB. Anything else is like trying to bail out a leaky boat with a bucket - you need to fix the underlying issue, or else all your hard work will be for nothing.

jamie

  • Hero Member
  • *****
  • Posts: 7486
Re: Possible cause of error
« Reply #3 on: October 21, 2025, 12:22:47 pm »
Try switching the last 2 lines in their order in the finalize.
The only true wisdom is knowing you know nothing

egsuh

  • Hero Member
  • *****
  • Posts: 1729
Re: Possible cause of error
« Reply #4 on: October 24, 2025, 09:27:20 am »
Code: Pascal  [Select][+][-]
  1. Try switching the last 2 lines in their order in the finalize.

That has no effect. BTW, that is not my file. WinProc.pp.

440bx

  • Hero Member
  • *****
  • Posts: 6016
Re: Possible cause of error
« Reply #5 on: October 24, 2025, 10:01:28 am »
I can point you in the right direction for you to figure out the cause of the problem...

You know the problem is with ChangeMenus but, you don't know why ChangedMenus is causing an A/V.

You should place a _hardware_ read/write breakpoint on the ChangeMenus variable.  That will cause execution to break every time ChangeMenus changes.  The first time is when it is allocated (I'm presuming it's a class), note the value of the pointer (it should remain unchanged throughout the program).  Every time it changes, execution should break, that should eventually reveal the culprit that caused it to be invalid which caused the A/V.

HTH.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 7486
Re: Possible cause of error
« Reply #6 on: October 24, 2025, 01:00:37 pm »
Are you using MDI forms?
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 18672
  • Jungle wars. And failing health it seems.
Re: Possible cause of error
« Reply #7 on: October 24, 2025, 06:56:21 pm »
I suspect the Atom is the cause:
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globaladdatoma
release the atom after the menu is freed.

Creation order and removal should be in opposite order.
« Last Edit: October 24, 2025, 07:16:41 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018