Possible cause of error lazarus / 31-LCL ---------------------------------------------------------------------- egsuh · 2025-10-21 05:47 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure DoInitialization;begin  DefaultWindowInfo := Default(TWin32WindowInfo);  DefaultWindowInfo.DrawItemIndex := -1;  WindowInfoAtom := Windows.GlobalAddAtom('WindowInfo');  ChangedMenus := TFPList.Create;  if WindowsVersion = wvUnknown then    UpdateWindowsVersion;end; {$IFDEF ASSERT_IS_ON}  {$UNDEF ASSERT_IS_ON}  {$C-}{$ENDIF} initialization  DoInitialization; finalization  Windows.GlobalDeleteAtom(WindowInfoAtom);  WindowInfoAtom := 0;  ChangedMenus.Free;  // <=========== error at here   FreeAndNil(PopupOwnersList); ---------------------------------------------------------------------- cdbc · 2025-10-21 06:11 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 ---------------------------------------------------------------------- H₂SO₄ · 2025-10-21 07:50 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 · 2025-10-21 10:22 Try switching the last 2 lines in their order in the finalize. ---------------------------------------------------------------------- egsuh · 2025-10-24 07:27 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2025-10-24 08:01 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. ---------------------------------------------------------------------- jamie · 2025-10-24 11:00 Are you using MDI forms? ---------------------------------------------------------------------- Thaddy · 2025-10-24 16:56 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.