View Issue Details

IDProjectCategoryView StatusLast Update
0036776LazarusIDEpublic2020-03-27 09:52
ReporterCyraxAssigned ToOndrej Pokorny 
PrioritynormalSeverityminorReproducibilityrandom
Status closedResolutionreopened 
PlatformLinux x86_64OSArchOS Version3.17.4-1
Product Version2.1 (SVN)Product Buildr62726 
Target Version2.2Fixed in Version 
Summary0036776: Bringing up a popup menu in the IDE sometimes causes Access Violation dialog to occur.
DescriptionThis happens when doing work in the source editor or changing build mode via quick button at the IDE toolbar.

This bug may be related to 36746
Additional Information
TApplication.HandleException: EAccessViolation
Access violation
  Stack trace:
  $00000000008F442C  GTK2MENUITEMSELECT,  line 191 of gtk2/gtk2wsmenus.pp
  $0000000000684E7E  TMENUITEM__CHECKCHILDRENHANDLES,  line 384 of include/menuitem.inc
  $00000000006833C5  TMENU__CREATEHANDLE,  line 153 of include/menu.inc
  $0000000000689380  TPOPUPMENU__POPUP,  line 79 of include/popupmenu.inc
  $00000000006892AA  TPOPUPMENU__POPUP,  line 66 of include/popupmenu.inc
  $0000000000C7F6E8  TSOURCEEDITOR__EDITORCHANGEUPDATING,  line 5615 of sourceeditor.pp
  $0000000000A0AB2D  TCUSTOMSYNEDIT__SETUPDATESTATE,  line 2416 of synedit.pp
  $0000000000A0B37E  TCUSTOMSYNEDIT__DODECPAINTLOCK,  line 2511 of synedit.pp
  $000000000074A747  TMETHODLIST__CALLNOTIFYEVENTS,  line 318 of lazmethodlist.pas
  $0000000000FC7E32  TSYNEDITSTRINGLIST__SENDNOTIFICATION,  line 1564 of synedittextbuffer.pp
  $0000000000FC4FC4  TSYNEDITSTRINGLIST__SETUPDATESTATE,  line 1267 of synedittextbuffer.pp
  $0000000000FBAED2  TSYNEDITSTRINGS__ENDUPDATE,  line 978 of lazsynedittext.pas
  $0000000000A0A953  TCUSTOMSYNEDIT__DECPAINTLOCK,  line 2391 of synedit.pp
  $0000000000A11AC0  TCUSTOMSYNEDIT__MOUSEUP,  line 3952 of synedit.pp
  $0000000000632CAC  TCONTROL__DOMOUSEUP,  line 2300 of include/control.inc
  $0000000000633C9F  TCONTROL__WMRBUTTONUP,  line 2803 of include/control.inc
  $000000000043C138  TOBJECT__DISPATCH,  line 684 of ../inc/objpas.inc
TagsNo tags attached.
Fixed in Revision62733
LazTarget-
WidgetsetGTK 2, GTK 3, Win32/Win64, Carbon, Cocoa, QT, QT5
Attached Files
  • ide_buildmodes_menuitems_fix.diff (480 bytes)
    Index: ide/mainbase.pas
    ===================================================================
    --- ide/mainbase.pas	(revision 62726)
    +++ ide/mainbase.pas	(working copy)
    @@ -361,8 +361,11 @@
       // fill the PopupMenu
       CurIndex := 0;
       if Project1<>nil then
    +  begin
    +    Items.Clear;
         for i:=0 to Project1.BuildModes.Count-1 do
           AddMode(i, Project1.BuildModes[i]);
    +  end;
       // remove unused menuitems
       while Items.Count > CurIndex do
         Items[Items.Count - 1].Free;
    
  • menuitem.inc.diff (1,290 bytes)
    diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc
    index c10850f8b8..cc1208c90d 100644
    --- a/lcl/include/menuitem.inc
    +++ b/lcl/include/menuitem.inc
    @@ -367,6 +367,7 @@ var
       i: Integer;
       AMenu: TMenu;
       AMergedItems: TMergedMenuItems;
    +  AMenuItem: TMenuItem;
     begin
       if FItems = nil then
         Exit;
    @@ -374,14 +375,21 @@ begin
       AMenu := GetMenu(Self);
       AMergedItems := MergedItems;
       for i := 0 to AMergedItems.InvisibleCount-1 do
    -    if AMergedItems.InvisibleItems[i].HandleAllocated then
    -      AMergedItems.InvisibleItems[i].DestroyHandle;
    +  begin
    +    AMenuItem := AMergedItems.InvisibleItems[i];
    +    if FItems.IndexOf(AMenuItem) >= 0 then
    +      if AMenuItem.HandleAllocated then
    +        AMenuItem.DestroyHandle;
    +  end;
     
       for i := 0 to AMergedItems.VisibleCount-1 do
       begin
    -    if AMergedItems.VisibleItems[i].HandleAllocated and (GetMenu(AMergedItems.VisibleItems[i]) <> AMenu) then
    -      AMergedItems.VisibleItems[i].DestroyHandle;
    -    AMergedItems.VisibleItems[i].HandleNeeded;
    +    AMenuItem := AMergedItems.VisibleItems[i];
    +    if FItems.IndexOf(AMenuItem) >= 0 then begin
    +      if AMenuItem.HandleAllocated and (GetMenu(AMenuItem) <> AMenu) then
    +        AMenuItem.DestroyHandle;
    +      AMenuItem.HandleNeeded;
    +    end;
       end;
     end;
     
    
    menuitem.inc.diff (1,290 bytes)
  • 0001-Revert-Zeljko-Hack.patch (1,905 bytes)
    From 993d93f33d8683054df6d499dd83c6f33e0010e5 Mon Sep 17 00:00:00 2001
    From: juha <juha.manninen62@gmail.com>
    Date: Tue, 10 Mar 2020 11:30:49 +0200
    Subject: [PATCH] Revert Zeljko Hack
    
    ---
     lcl/include/menuitem.inc | 22 ++++------------------
     1 file changed, 4 insertions(+), 18 deletions(-)
    
    diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc
    index 3c6db08ba..d5cafe944 100644
    --- a/lcl/include/menuitem.inc
    +++ b/lcl/include/menuitem.inc
    @@ -364,29 +364,15 @@ begin
     
       AMenu := GetMenu(Self);
       AMergedItems := MergedItems;
    -
    -  // issue #36776
    -  if FItems.Count <> AMergedItems.InvisibleCount + AMergedItems.VisibleCount then
    -  begin
    -    DebugLn(Format('WARNING: TMenuItem.CheckChildrenHandles(%s): items %d invisibleCount %d visibleCount %d',
    -      [dbgsName(Self),FItems.Count, AMergedItems.InvisibleCount, AMergedItems.VisibleCount]));
    -    for i := 0 to FItems.Count - 1 do
    -      if Assigned(FItems[i]) then
    -        DebugLn(Format('Item[%d] %s',[i, dbgsName(TMenuItem(FItems[i]))]));
    -  end;
    -
       for i := 0 to AMergedItems.InvisibleCount-1 do
    -    if (FItems.IndexOf(AMergedItems.InvisibleItems[i]) >= 0) and AMergedItems.InvisibleItems[i].HandleAllocated then
    +    if AMergedItems.InvisibleItems[i].HandleAllocated then
           AMergedItems.InvisibleItems[i].DestroyHandle;
     
       for i := 0 to AMergedItems.VisibleCount-1 do
       begin
    -    if (FItems.IndexOf(AMergedItems.VisibleItems[i]) >= 0) then
    -    begin
    -      if AMergedItems.VisibleItems[i].HandleAllocated and (GetMenu(AMergedItems.VisibleItems[i]) <> AMenu) then
    -        AMergedItems.VisibleItems[i].DestroyHandle;
    -      AMergedItems.VisibleItems[i].HandleNeeded;
    -    end;
    +    if AMergedItems.VisibleItems[i].HandleAllocated and (GetMenu(AMergedItems.VisibleItems[i]) <> AMenu) then
    +      AMergedItems.VisibleItems[i].DestroyHandle;
    +    AMergedItems.VisibleItems[i].HandleNeeded;
       end;
     end;
     
    -- 
    2.25.1
    
    

Relationships

related to 0036582 resolvedOndrej Pokorny Lazarus MDI support for Windows (patch and demo included) 
related to 0036746 resolvedOndrej Pokorny Patches Removing sub menu causes crash 

Activities

Cyrax

2020-03-09 16:24

reporter   ~0121493

Call stack

#0 TMENUITEM__CHECKCHILDRENHANDLES(0x49ff788) at include/menuitem.inc:390
0000001 TMENU__CREATEHANDLE(0x4785c68) at include/menu.inc:153
0000002 TPOPUPMENU__POPUP(0x4785c68, 444, 382) at include/popupmenu.inc:79
0000003 TPOPUPMENU__POPUP(0x4785c68) at include/popupmenu.inc:66
0000004 TSOURCEEDITOR__EDITORCHANGEUPDATING(0x47efc88, 0x4a751b8, false) at sourceeditor.pp:5615
0000005 TCUSTOMSYNEDIT__SETUPDATESTATE(0x4a751b8, false, 0x4a751b8) at synedit.pp:2416
0000006 TCUSTOMSYNEDIT__DODECPAINTLOCK(0x4a751b8, 0x4a751b8) at synedit.pp:2511
0000007 TMETHODLIST__CALLNOTIFYEVENTS(0x4a76678, 0x4a751b8) at lazmethodlist.pas:318
0000008 TSYNEDITSTRINGLIST__SENDNOTIFICATION(0x47f9208, SENRDECPAINTLOCK, 0x4a751b8) at synedittextbuffer.pp:1564
0000009 TSYNEDITSTRINGLIST__SETUPDATESTATE(0x47f9208, false, 0x4a751b8) at synedittextbuffer.pp:1267
0000010 TSYNEDITSTRINGS__ENDUPDATE(0x47f9208, 0x4a751b8) at lazsynedittext.pas:978
0000011 TCUSTOMSYNEDIT__DECPAINTLOCK(0x4a751b8) at synedit.pp:2391
0000012 TCUSTOMSYNEDIT__MOUSEUP(0x4a751b8, MBRIGHT, [], 149, 159) at synedit.pp:3952
0000013 TCONTROL__DOMOUSEUP(0x4a751b8, {MSG = 517, KEYS = 0, XPOS = 149, YPOS = 159, POS = {X = 149, Y = 159}, DUMMY = 6148914689815281813, RESULT = 0}, MBRIGHT) at include/control.inc:2300
0000014 TCONTROL__WMRBUTTONUP(0x4a751b8, {MSG = 517, KEYS = 0, XPOS = 149, YPOS = 159, POS = {X = 149, Y = 159}, DUMMY = 6148914689815281813, RESULT = 0}) at include/control.inc:2803
0000015 TOBJECT__DISPATCH(0x4a751b8, ) at ../inc/objpas.inc:684
0000016 TCONTROL__WNDPROC(0x4a751b8, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689815281813, RESULT = 0}) at include/control.inc:2240
0000017 TWINCONTROL__WNDPROC(0x4a751b8, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689815281813, RESULT = 0}) at include/wincontrol.inc:5429
0000018 TCUSTOMSYNEDIT__WNDPROC(0x4a751b8, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689815281813, RESULT = 0}) at synedit.pp:6221
0000019 DELIVERMESSAGE(0x4a751b8, ) at lclmessageglue.pas:112
0000020 DELIVERMESSAGE(0x4a751b8, ) at gtk2/gtk2proc.inc:3737
0000021 DELIVERMOUSEUPMESSAGE(0x4a49c70, 0x6a20740, 0x4a751b8) at gtk2/gtk2callback.inc:2205
0000022 GTKMOUSEBTNRELEASE(0x4621000, 0x6a20740, 0x4a751b8) at gtk2/gtk2callback.inc:2282
0000023 ?? at :0
0000024 g_closure_invoke at :0
0000025 ?? at :0
0000026 g_signal_emit_valist at :0
0000027 g_signal_emit at :0
0000028 ?? at :0
0000029 gtk_propagate_event at :0
0000030 gtk_main_do_event at :0
0000031 ?? at :0
0000032 g_main_context_dispatch at :0
0000033 ?? at :0
0000034 g_main_context_iteration at :0
0000035 TGTK2WIDGETSET__APPWAITMESSAGE(0x2a3fd58) at gtk2/gtk2widgetset.inc:2433
0000036 TAPPLICATION__IDLE(0x2a3d8d8, true) at include/application.inc:397
0000037 TAPPLICATION__HANDLEMESSAGE(0x2a3d8d8) at include/application.inc:1211
0000038 TAPPLICATION__RUNLOOP(0x2a3d8d8) at include/application.inc:1329
0000039 TWIDGETSET__APPRUN(0x2a3fd58, {Proc = {procedure (POINTER)} 0x7fffffffe2b0, Self = 0x2a3d8d8}) at include/interfacebase.inc:54
0000040 TAPPLICATION__RUN(0x2a3d8d8) at include/application.inc:1317
0000041 main at lazarus.pp:153

Zeljan Rikalo

2020-03-09 17:52

developer   ~0121495

Last edited: 2020-03-09 20:48

View 2 revisions

It's IDE problem and it's reproducable on all widgetsets, possible patch attached .... someone comfortable with IDE should check it.

That happens since inside TMenuItem.CheckChildrenHandles count of FItems is different (less items) than InvisibleCount + VisibleCount. Please test with attached patch



ide_buildmodes_menuitems_fix.diff (480 bytes)
Index: ide/mainbase.pas
===================================================================
--- ide/mainbase.pas	(revision 62726)
+++ ide/mainbase.pas	(working copy)
@@ -361,8 +361,11 @@
   // fill the PopupMenu
   CurIndex := 0;
   if Project1<>nil then
+  begin
+    Items.Clear;
     for i:=0 to Project1.BuildModes.Count-1 do
       AddMode(i, Project1.BuildModes[i]);
+  end;
   // remove unused menuitems
   while Items.Count > CurIndex do
     Items[Items.Count - 1].Free;

Cyrax

2020-03-09 18:43

reporter   ~0121498

Applied the patch but no dice. Crashes as usual.

#0 TMENUITEM__CHECKCHILDRENHANDLES(0x48204b8) at include/menuitem.inc:384
0000001 TMENU__CREATEHANDLE(0x4820388) at include/menu.inc:153
0000002 TPOPUPMENU__POPUP(0x4820388, 676, 448) at include/popupmenu.inc:79
0000003 TPOPUPMENU__POPUP(0x4820388) at include/popupmenu.inc:66
0000004 TSOURCEEDITOR__EDITORCHANGEUPDATING(0x4c2c658, 0x4c30008, false) at sourceeditor.pp:5615
0000005 TCUSTOMSYNEDIT__SETUPDATESTATE(0x4c30008, false, 0x4c30008) at synedit.pp:2416
0000006 TCUSTOMSYNEDIT__DODECPAINTLOCK(0x4c30008, 0x4c30008) at synedit.pp:2511
0000007 TMETHODLIST__CALLNOTIFYEVENTS(0x4c31178, 0x4c30008) at lazmethodlist.pas:318
0000008 TSYNEDITSTRINGLIST__SENDNOTIFICATION(0x4c30af8, SENRDECPAINTLOCK, 0x4c30008) at synedittextbuffer.pp:1564
0000009 TSYNEDITSTRINGLIST__SETUPDATESTATE(0x4c30af8, false, 0x4c30008) at synedittextbuffer.pp:1267
0000010 TSYNEDITSTRINGS__ENDUPDATE(0x4c30af8, 0x4c30008) at lazsynedittext.pas:978
0000011 TCUSTOMSYNEDIT__DECPAINTLOCK(0x4c30008) at synedit.pp:2391
0000012 TCUSTOMSYNEDIT__MOUSEUP(0x4c30008, MBRIGHT, [], 381, 225) at synedit.pp:3952
0000013 TCONTROL__DOMOUSEUP(0x4c30008, {MSG = 517, KEYS = 0, XPOS = 381, YPOS = 225, POS = {X = 381, Y = 225}, DUMMY = 6148914689819607421, RESULT = 0}, MBRIGHT) at include/control.inc:2300
0000014 TCONTROL__WMRBUTTONUP(0x4c30008, {MSG = 517, KEYS = 0, XPOS = 381, YPOS = 225, POS = {X = 381, Y = 225}, DUMMY = 6148914689819607421, RESULT = 0}) at include/control.inc:2803
0000015 TOBJECT__DISPATCH(0x4c30008, ) at ../inc/objpas.inc:684
0000016 TCONTROL__WNDPROC(0x4c30008, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689819607421, RESULT = 0}) at include/control.inc:2240
0000017 TWINCONTROL__WNDPROC(0x4c30008, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689819607421, RESULT = 0}) at include/wincontrol.inc:5429
0000018 TCUSTOMSYNEDIT__WNDPROC(0x4c30008, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689819607421, RESULT = 0}) at synedit.pp:6221
0000019 DELIVERMESSAGE(0x4c30008, ) at lclmessageglue.pas:112
0000020 DELIVERMESSAGE(0x4c30008, ) at gtk2/gtk2proc.inc:3737
0000021 DELIVERMOUSEUPMESSAGE(0x4d6c5b0, 0x469e420, 0x4c30008) at gtk2/gtk2callback.inc:2205
0000022 GTKMOUSEBTNRELEASE(0x47dba30, 0x469e420, 0x4c30008) at gtk2/gtk2callback.inc:2282
0000023 ?? at :0
0000024 g_closure_invoke at :0
0000025 ?? at :0
0000026 g_signal_emit_valist at :0
0000027 g_signal_emit at :0
0000028 ?? at :0
0000029 gtk_propagate_event at :0
0000030 gtk_main_do_event at :0
0000031 ?? at :0
0000032 g_main_context_dispatch at :0
0000033 ?? at :0
0000034 g_main_context_iteration at :0
0000035 TGTK2WIDGETSET__APPWAITMESSAGE(0x2a68d58) at gtk2/gtk2widgetset.inc:2433
0000036 TAPPLICATION__IDLE(0x2a668d8, true) at include/application.inc:397
0000037 TAPPLICATION__HANDLEMESSAGE(0x2a668d8) at include/application.inc:1211
0000038 TAPPLICATION__RUNLOOP(0x2a668d8) at include/application.inc:1329
0000039 TWIDGETSET__APPRUN(0x2a68d58, {Proc = {procedure (POINTER)} 0x7fffffffe2b0, Self = 0x2a668d8}) at include/interfacebase.inc:54
0000040 TAPPLICATION__RUN(0x2a668d8) at include/application.inc:1317
0000041 main at lazarus.pp:153

Juha Manninen

2020-03-09 18:50

developer   ~0121499

Last edited: 2020-03-09 18:53

View 2 revisions

Zeljko, your patch affects only BuildModes menu. The call stack shows SynEdit mouse actions. Looks like editor popup menu.
I cannot reproduce with any menu for some reason. Testing now with QT5.
Cyrax, are there steps to follow for reproducing it every time?

Cyrax

2020-03-09 18:56

reporter   ~0121500

No, it happens randomly. You should try to keep right clicking on source editor and accessing functionalities of the source editor popup menu, namely "Find declaration of <x>" etc.

Zeljan Rikalo

2020-03-09 19:05

developer   ~0121501

@Juha, @Cyrax it can be always reproduced with 2 projects with different number od build modes. Just open one with more build modes an then another one with less build modes (in between click buld modes menu).
Problem IS inside TMenuItem.CheckChildrenHandles() FItems.Count is different than InvisibleCount + VisibleCount.
Workaround is to set in both loops (or remove r62685 at all)
if FItems.IndexOf(InvisibleItems[i]) >= 0 then
 .....

if FItems.IndexOf(VisibleItems[i]) >= 0 then
 .....

But it's only workaround. Popup menu should be cleared before rebuilding otherwise there are dangling items in VisibleItems[] or InvisibleItems[].
I know that it's changed in r62685 (and without that revision everything works fine), but IMO Lazarus IDE should be fixed to work in proper way without semi hacks.

Cyrax

2020-03-09 20:02

reporter   ~0121503

Attached patch that may fix this bug.

menuitem.inc.diff (1,290 bytes)
diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc
index c10850f8b8..cc1208c90d 100644
--- a/lcl/include/menuitem.inc
+++ b/lcl/include/menuitem.inc
@@ -367,6 +367,7 @@ var
   i: Integer;
   AMenu: TMenu;
   AMergedItems: TMergedMenuItems;
+  AMenuItem: TMenuItem;
 begin
   if FItems = nil then
     Exit;
@@ -374,14 +375,21 @@ begin
   AMenu := GetMenu(Self);
   AMergedItems := MergedItems;
   for i := 0 to AMergedItems.InvisibleCount-1 do
-    if AMergedItems.InvisibleItems[i].HandleAllocated then
-      AMergedItems.InvisibleItems[i].DestroyHandle;
+  begin
+    AMenuItem := AMergedItems.InvisibleItems[i];
+    if FItems.IndexOf(AMenuItem) >= 0 then
+      if AMenuItem.HandleAllocated then
+        AMenuItem.DestroyHandle;
+  end;
 
   for i := 0 to AMergedItems.VisibleCount-1 do
   begin
-    if AMergedItems.VisibleItems[i].HandleAllocated and (GetMenu(AMergedItems.VisibleItems[i]) <> AMenu) then
-      AMergedItems.VisibleItems[i].DestroyHandle;
-    AMergedItems.VisibleItems[i].HandleNeeded;
+    AMenuItem := AMergedItems.VisibleItems[i];
+    if FItems.IndexOf(AMenuItem) >= 0 then begin
+      if AMenuItem.HandleAllocated and (GetMenu(AMenuItem) <> AMenu) then
+        AMenuItem.DestroyHandle;
+      AMenuItem.HandleNeeded;
+    end;
   end;
 end;
 
menuitem.inc.diff (1,290 bytes)

Juha Manninen

2020-03-09 20:26

developer   ~0121504

Last edited: 2020-03-09 20:54

View 4 revisions

r62685 is "LCL: implement MDI for win32. Issue 36582, based on patch by Kostas Michalopoulos" by Ondrej. Issue 0036582.
It means this is not related to my 0036746 which changed TMenuItem.Clear.
Yes, I guess the IDE's code must be fixed by clearing a menu's items before filling it.

[Edit] Cyrax, what happens to AMenuItem not found in FItems?

I realized that the IDE reuses MenuItems in many places. For example the BuildMode code in unit MainBase could be simplified after adding Zeljko's Items.Clear line.
The code either uses an existing MenuItem or creates a new one. Finally it does:
   // remove unused menuitems
   while Items.Count > CurIndex do
     Items[Items.Count - 1].Free;
Is such an optimization worth the trouble and extra complexity? I doubt.

Cyrax

2020-03-09 22:19

reporter   ~0121506

>[Edit] Cyrax, what happens to AMenuItem not found in FItems?
Nothing. In my testings, I have found no side effects if it is not found in FItems. Both if FItems.IndexOf(AMenuItem) >= 0 then clauses are based on Zeljan's suggestion.

Juha Manninen

2020-03-10 00:05

developer   ~0121515

Please see my r62728. It turned TMenuItem.Delete into a function returning the TMenuItem. Yes, it is compatible with Delphi as the result can be ignored.
The fundamental error was that the unused MenuItems were not Deleted from the list, they were only freed.
The same error was in TMenuItem.Clear (issue 0036746) which got fixed.
I didn't find a similar optimization in popup menus of source editor. I also cannot reproduce the bug in it.
I could finally reproduce in BuildMode menu after switching projects.

Cyrax

2020-03-10 06:37

reporter   ~0121519

FPC trunk r44289.

Make commands for building FPC trunk are
make clean all install OS_TARGET=linux CPU_TARGET=x86_64 OPT="-gw2 -godwarfsets -godwarfmethodclassprefix -gl -O- -Xs- -Si- -vbq -Sew- -XX- -CX- -dEXTDEBUG -vh- -vn- -vw- -dDEBUG_NODE_XML -Cit -gt -gv -Cg  -Fl/lib -Fl/usr/lib -Fl/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0" FPC=fpc REVSTR=44289 IDE=1 NOWPOCYCLE=1 ALLOW_WARNINGS=1 LINKSMART=0 CREATESMART=0 INSTALL_PREFIX="/mnt/shares/ohjelmointi2/fpc/x86_64/trunk/3.3.1/binary/trunk"


----

Lazarus trunk 62732.

Make commands for building Lazarus trunk are
make clean all FPC=fpc OPT="-gw2 -godwarfsets -godwarfmethodclassprefix -gl -O- -Si- -vb -vh- -vn- -vw- -dDBG_WITH_DEBUGGER_DEBUG  -Cit -gt -gv" UPXPROG=echo USESVN2REVISIONINC=0


GNU ld (GNU Binutils) 2.34
gcc (Arch Linux 9.2.1+20200130-2) 9.2.1 20200130
gtk2 2.24.32-2
glibc 2.31-1
gdb 9.1-1


---

Invoking popup menu by normal usage of editor sources still produces crash.

#0 ?? at :0
0000001 TMENUITEM__CHECKCHILDRENHANDLES(0x494d408) at include/menuitem.inc:375
0000002 TMENUITEM__CREATEHANDLE(0x494d408) at include/menuitem.inc:137
0000003 TMENUITEM__HANDLENEEDED(0x494d408) at include/menuitem.inc:737
0000004 TMENUITEM__CHECKCHILDRENHANDLES(0x48be3c8) at include/menuitem.inc:375
0000005 TMENU__CREATEHANDLE(0x4942208) at include/menu.inc:153
0000006 TPOPUPMENU__POPUP(0x4942208, 461, 232) at include/popupmenu.inc:79
0000007 TPOPUPMENU__POPUP(0x4942208) at include/popupmenu.inc:66
0000008 TSOURCEEDITOR__EDITORCHANGEUPDATING(0x47a3cb8, 0x6b37668, false) at sourceeditor.pp:5615
0000009 TCUSTOMSYNEDIT__SETUPDATESTATE(0x6b37668, false, 0x6b37668) at synedit.pp:2416
0000010 TCUSTOMSYNEDIT__DODECPAINTLOCK(0x6b37668, 0x6b37668) at synedit.pp:2511
0000011 TMETHODLIST__CALLNOTIFYEVENTS(0x6b38b18, 0x6b37668) at lazmethodlist.pas:318
0000012 TSYNEDITSTRINGLIST__SENDNOTIFICATION(0x6b38418, SENRDECPAINTLOCK, 0x6b37668) at synedittextbuffer.pp:1564
0000013 TSYNEDITSTRINGLIST__SETUPDATESTATE(0x6b38418, false, 0x6b37668) at synedittextbuffer.pp:1267
0000014 TSYNEDITSTRINGS__ENDUPDATE(0x6b38418, 0x6b37668) at lazsynedittext.pas:978
0000015 TCUSTOMSYNEDIT__DECPAINTLOCK(0x6b37668) at synedit.pp:2391
0000016 TCUSTOMSYNEDIT__MOUSEUP(0x6b37668, MBRIGHT, [], 166, 9) at synedit.pp:3952
0000017 TCONTROL__DOMOUSEUP(0x6b37668, {MSG = 517, KEYS = 0, XPOS = 166, YPOS = 9, POS = {X = 166, Y = 9}, DUMMY = 6148914689805451430, RESULT = 0}, MBRIGHT) at include/control.inc:2300
0000018 TCONTROL__WMRBUTTONUP(0x6b37668, {MSG = 517, KEYS = 0, XPOS = 166, YPOS = 9, POS = {X = 166, Y = 9}, DUMMY = 6148914689805451430, RESULT = 0}) at include/control.inc:2803
0000019 TOBJECT__DISPATCH(0x6b37668, ) at ../inc/objpas.inc:684
0000020 TCONTROL__WNDPROC(0x6b37668, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689805451430, RESULT = 0}) at include/control.inc:2240
0000021 TWINCONTROL__WNDPROC(0x6b37668, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689805451430, RESULT = 0}) at include/wincontrol.inc:5429
0000022 TCUSTOMSYNEDIT__WNDPROC(0x6b37668, {MSG = 517, UNUSEDMSG = 1431655765, WPARAM = 0, LPARAM = 6148914689805451430, RESULT = 0}) at synedit.pp:6221
0000023 DELIVERMESSAGE(0x6b37668, ) at lclmessageglue.pas:112
0000024 DELIVERMESSAGE(0x6b37668, ) at gtk2/gtk2proc.inc:3737
0000025 DELIVERMOUSEUPMESSAGE(0x4bfe250, 0x4750a70, 0x6b37668) at gtk2/gtk2callback.inc:2205
0000026 GTKMOUSEBTNRELEASE(0x6a0cf00, 0x4750a70, 0x6b37668) at gtk2/gtk2callback.inc:2282
0000027 ?? at :0
0000028 g_closure_invoke at :0
0000029 ?? at :0
0000030 g_signal_emit_valist at :0
0000031 g_signal_emit at :0
0000032 ?? at :0
0000033 gtk_propagate_event at :0
0000034 gtk_main_do_event at :0
0000035 ?? at :0
0000036 g_main_context_dispatch at :0
0000037 ?? at :0
0000038 g_main_context_iteration at :0
0000039 TGTK2WIDGETSET__APPWAITMESSAGE(0x2a68d58) at gtk2/gtk2widgetset.inc:2433
0000040 TAPPLICATION__IDLE(0x2a668d8, true) at include/application.inc:397
0000041 TAPPLICATION__HANDLEMESSAGE(0x2a668d8) at include/application.inc:1211
0000042 TAPPLICATION__RUNLOOP(0x2a668d8) at include/application.inc:1329
0000043 TWIDGETSET__APPRUN(0x2a68d58, {Proc = {procedure (POINTER)} 0x7fffffffe2b0, Self = 0x2a668d8}) at include/interfacebase.inc:54
0000044 TAPPLICATION__RUN(0x2a668d8) at include/application.inc:1317
0000045 main at lazarus.pp:153

Zeljan Rikalo

2020-03-10 09:47

developer   ~0121526

I've added my first idea - check FItems.IndexOf() but also warning will be thrown so we know where miscounted menu comes from.

Juha Manninen

2020-03-10 10:39

developer   ~0121528

Last edited: 2020-03-10 10:57

View 3 revisions

I was just going to fix it properly...
Can you please test with r62734. I guess you should revert Zeljko's commit when testing. I upload a patch to make it easier.
I still could not reproduce the crash but that is how memory issues often work. They occur only with some machines / configurations.

Zeljko's solution is a hack, it is not needed when a menu is used properly.
It also adds overhead and slowdown with a linear search.
It can be used as a way to debug remaining problems though.



0001-Revert-Zeljko-Hack.patch (1,905 bytes)
From 993d93f33d8683054df6d499dd83c6f33e0010e5 Mon Sep 17 00:00:00 2001
From: juha <juha.manninen62@gmail.com>
Date: Tue, 10 Mar 2020 11:30:49 +0200
Subject: [PATCH] Revert Zeljko Hack

---
 lcl/include/menuitem.inc | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc
index 3c6db08ba..d5cafe944 100644
--- a/lcl/include/menuitem.inc
+++ b/lcl/include/menuitem.inc
@@ -364,29 +364,15 @@ begin
 
   AMenu := GetMenu(Self);
   AMergedItems := MergedItems;
-
-  // issue #36776
-  if FItems.Count <> AMergedItems.InvisibleCount + AMergedItems.VisibleCount then
-  begin
-    DebugLn(Format('WARNING: TMenuItem.CheckChildrenHandles(%s): items %d invisibleCount %d visibleCount %d',
-      [dbgsName(Self),FItems.Count, AMergedItems.InvisibleCount, AMergedItems.VisibleCount]));
-    for i := 0 to FItems.Count - 1 do
-      if Assigned(FItems[i]) then
-        DebugLn(Format('Item[%d] %s',[i, dbgsName(TMenuItem(FItems[i]))]));
-  end;
-
   for i := 0 to AMergedItems.InvisibleCount-1 do
-    if (FItems.IndexOf(AMergedItems.InvisibleItems[i]) >= 0) and AMergedItems.InvisibleItems[i].HandleAllocated then
+    if AMergedItems.InvisibleItems[i].HandleAllocated then
       AMergedItems.InvisibleItems[i].DestroyHandle;
 
   for i := 0 to AMergedItems.VisibleCount-1 do
   begin
-    if (FItems.IndexOf(AMergedItems.VisibleItems[i]) >= 0) then
-    begin
-      if AMergedItems.VisibleItems[i].HandleAllocated and (GetMenu(AMergedItems.VisibleItems[i]) <> AMenu) then
-        AMergedItems.VisibleItems[i].DestroyHandle;
-      AMergedItems.VisibleItems[i].HandleNeeded;
-    end;
+    if AMergedItems.VisibleItems[i].HandleAllocated and (GetMenu(AMergedItems.VisibleItems[i]) <> AMenu) then
+      AMergedItems.VisibleItems[i].DestroyHandle;
+    AMergedItems.VisibleItems[i].HandleNeeded;
   end;
 end;
 
-- 
2.25.1

Zeljan Rikalo

2020-03-10 13:17

developer   ~0121533

@Juha, I know that my commit is workaround , please leave it inside proc as long as WARNING about count mismatch is thrown into debug console, also
there's another error which is IMO more dangerous and it's not related to the menus. See 0036782.

Ondrej Pokorny

2020-03-12 10:39

developer   ~0121567

It should be fixed. Please reopen if it isn't, otherwise close. Thanks.

Cyrax

2020-03-27 09:52

reporter   ~0121728

Fixed due to added improved MDI code at trunk r62745. Closing.

Issue History

Date Modified Username Field Change
2020-03-09 14:28 Cyrax New Issue
2020-03-09 15:23 Juha Manninen Relationship added related to 0036746
2020-03-09 16:24 Cyrax Note Added: 0121493
2020-03-09 17:52 Zeljan Rikalo File Added: ide_buildmodes_menuitems_fix.diff
2020-03-09 17:52 Zeljan Rikalo Note Added: 0121495
2020-03-09 18:43 Cyrax Note Added: 0121498
2020-03-09 18:50 Juha Manninen Note Added: 0121499
2020-03-09 18:53 Juha Manninen Note Edited: 0121499 View Revisions
2020-03-09 18:56 Cyrax Note Added: 0121500
2020-03-09 19:05 Zeljan Rikalo Note Added: 0121501
2020-03-09 20:02 Cyrax File Added: menuitem.inc.diff
2020-03-09 20:02 Cyrax Note Added: 0121503
2020-03-09 20:26 Juha Manninen Note Added: 0121504
2020-03-09 20:26 Juha Manninen Relationship added related to 0036582
2020-03-09 20:29 Juha Manninen Note Edited: 0121504 View Revisions
2020-03-09 20:35 Juha Manninen Note Edited: 0121504 View Revisions
2020-03-09 20:35 Juha Manninen Relationship deleted related to 0036746
2020-03-09 20:48 Juha Manninen Note Edited: 0121495 View Revisions
2020-03-09 20:54 Juha Manninen Note Edited: 0121504 View Revisions
2020-03-09 22:19 Cyrax Note Added: 0121506
2020-03-09 22:28 Juha Manninen Relationship added related to 0036746
2020-03-10 00:05 Juha Manninen Note Added: 0121515
2020-03-10 06:37 Cyrax Note Added: 0121519
2020-03-10 09:47 Zeljan Rikalo Assigned To => Zeljan Rikalo
2020-03-10 09:47 Zeljan Rikalo Status new => resolved
2020-03-10 09:47 Zeljan Rikalo Resolution open => fixed
2020-03-10 09:47 Zeljan Rikalo Fixed in Revision => 62733
2020-03-10 09:47 Zeljan Rikalo LazTarget => -
2020-03-10 09:47 Zeljan Rikalo Widgetset GTK 2 => GTK 2, GTK 3, Win32/Win64, Carbon, Cocoa, QT, QT5
2020-03-10 09:47 Zeljan Rikalo Note Added: 0121526
2020-03-10 10:34 Juha Manninen Assigned To Zeljan Rikalo => Juha Manninen
2020-03-10 10:38 Juha Manninen Status resolved => assigned
2020-03-10 10:38 Juha Manninen Resolution fixed => reopened
2020-03-10 10:39 Juha Manninen File Added: 0001-Revert-Zeljko-Hack.patch
2020-03-10 10:39 Juha Manninen Note Added: 0121528
2020-03-10 10:41 Juha Manninen Note Edited: 0121528 View Revisions
2020-03-10 10:42 Juha Manninen Status assigned => feedback
2020-03-10 10:57 Juha Manninen Note Edited: 0121528 View Revisions
2020-03-10 13:17 Zeljan Rikalo Note Added: 0121533
2020-03-10 14:27 Juha Manninen Target Version => 2.2
2020-03-10 14:27 Juha Manninen Widgetset GTK 2, GTK 3, Win32/Win64, Carbon, Cocoa, QT, QT5 => GTK 2, GTK 3, Win32/Win64, Carbon, Cocoa, QT, QT5
2020-03-12 08:44 Ondrej Pokorny Assigned To Juha Manninen => Ondrej Pokorny
2020-03-12 10:39 Ondrej Pokorny Status feedback => resolved
2020-03-12 10:39 Ondrej Pokorny Widgetset GTK 2, GTK 3, Win32/Win64, Carbon, Cocoa, QT, QT5 => GTK 2, GTK 3, Win32/Win64, Carbon, Cocoa, QT, QT5
2020-03-12 10:39 Ondrej Pokorny Note Added: 0121567
2020-03-27 09:52 Cyrax Status resolved => closed
2020-03-27 09:52 Cyrax Note Added: 0121728