View Issue Details

IDProjectCategoryView StatusLast Update
0019972Packages-public2014-09-21 18:10
ReporterTommi Prami Assigned ToFelipe Monteiro de Carvalho  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Product Version0.9.30.1 (SVN) 
Fixed in Version0.9.31 (SVN) 
Summary0019972: Crash while closing a modal window on WinCE
DescriptionAccess violations and other exceptiosn while closing window with MainMenu.

On Emulator I get lot of exceptions, and on the Device usually the program will Crash.

Trivial test program attached

Additional Information(There might also be bug while closing from that have no menus, but I can't confirm this.)

I use latest SVN version of Lazarus Revision (about) 31958
FPC 2.4.4
Windows Mobile 6.5
TagsNo tags attached.
Fixed in Revision32539
LazTarget-
WidgetsetWinCE
Attached Files

Relationships

related to 0019898 resolvedFelipe Monteiro de Carvalho Lazarus [WinCE] Sometimes an access violation or a bus error occurs when creating a form with a menu 
related to 0020029 resolvedFelipe Monteiro de Carvalho FPC Linking error in Free Pascal for WinCE "unknown pseudo-op .secrel32" 
related to 0020274 resolvedFelipe Monteiro de Carvalho Lazarus [WinCE] Access Violation when freeing a menu item (follow up of 0019898
related to 0026757 assignedStephano Lazarus [Patch] AV when destroying form with menu 

Activities

2011-08-12 14:40

 

MenuTest.zip (128,533 bytes)

Felipe Monteiro de Carvalho

2011-09-13 13:23

developer   ~0051775

Obviously a simple application with a menu does not crash, or at least didn't so either there is something special in your test project or this is a regression.

1> Does a minimal form with a menu also crash? If not, what exactly in
your example makes it crash?

2> If this is a regression, could you find the revision which broke
it? For instructions see:
http://wiki.lazarus.freepascal.org/How_To_Help_Developing_Lazarus#Dealing_with_regressions

3> Where is the stack trace for the exception?

Felipe Monteiro de Carvalho

2011-09-14 15:05

developer   ~0051813

You should have posted clear instructions about how to reproduce, but I will do it for you:

1> Open the application
2> Open the right menu and select open new window
3> Click in the close button of this second window

And then it crashes.

It works fine if you use Show instead of ShowModal.

2011-09-15 11:06

 

MenuTest_2.zip (130,320 bytes)

Tommi Prami

2011-09-15 11:12

reporter   ~0051848

I made some Changes into the Test App (MenuTest_z.zip)

1. Start the App
2. choose brUseShow RadioButton
3. Click "Open New Windows (No free)" menu
4. Click Close -> Just Close
5. Click btnFreeSecondatyForm to free up the form

This also crash.

But I think that Opening the form with ShowModal and setting the ModalResult will crash everytime.

And using the Show is not ideal for me (And crashing at the Shutdown of the APP) because in many places I need to wait the Form to close (Like ShowModal blocks until form is closed)

And doing something like this would be Ugly Hack

FForm.Show;

while FForm.Visible do
begin
  Application.ProcessMessages;
  Sleep(20); // to avoind hogging the CPU time
end;

Zaher Dirkey

2011-09-17 20:35

reporter   ~0051956

I uploaded temporary patch fix for this bug, test it please.

2011-09-17 20:35

 

MainMenuModalCrash.patch (550 bytes)   
Index: wincewinapi.inc
===================================================================
--- wincewinapi.inc	(revision 32239)
+++ wincewinapi.inc	(working copy)
@@ -2964,7 +2964,10 @@
   begin
     for i := 0 to WinCEWSMenus.MenuHandleList.Count - 1 do
       if WinCEWSMenus.MenuHandleList.Items[i] = Pointer(AMenuHandle) then Break;
-    lLCLMenu := TMenu(MenuLCLObjectList.Items[i]);
+    if i < MenuLCLObjectList.Count then
+      lLCLMenu := TMenu(MenuLCLObjectList.Items[i])
+    else
+      lLCLMenu := nil;
   end;
 
   {$ifdef Win32}
MainMenuModalCrash.patch (550 bytes)   

Tommi Prami

2011-09-19 15:30

reporter   ~0052028

Hello,

It did not work for me. Still some problems. (seems same to me). Or I did not know how to apply the Patch. I manually updated the file and then build the Ide again (With the Tools -> Build Lazarus... Menu).

And tried the Demo program I've made.

Still crashed similarly (or same way)

.-Tee-.

Tommi Prami

2011-09-19 18:33

reporter   ~0052034

And the CallStack is

#0 WINCEWSMENUS_TWINCEWSMENUITEM_$__DESTROYHANDLE$TMENUITEM at :0
0000001 MENUS_TMENUITEM_$__DESTROYHANDLE at :0
0000002 MENUS_TMENUITEM_$__DESTROYHANDLE at :0
0000003 MENUS_TMENUITEM_$__DESTROYHANDLE at :0
0000004 MENUS_TMENU_$__DESTROYHANDLE at :0
0000005 FORMS_TCUSTOMFORM_$__DESTROYWND at :0
0000006 CONTROLS_TWINCONTROL_$__DESTROYHANDLE at :0
0000007 FORMS_TCUSTOMFORM_$__SHOWMODAL$$LONGINT at :0
0000008 TFRMMAIN__MNUOPENFORM2CLICK((^TOBJECT) 0x1aa17a0, (TFRMMAIN) 0x1a977f0) at MainForm.pas:70
0000009 MENUS_TMENUITEM_$__CLICK at :0
0000010 MENUS_TMENUITEM_$__DOCLICKED$formal at :0
0000011 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
0000012 WINCEINT_WINDOWPROC$LONGWORD$LONGWORD$LONGWORD$LONGINT$$LONGINT at :0
0000013 ?? at :0
0000014 ?? at :0

Tommi Prami

2011-09-20 13:17

reporter   ~0052062

Hello again...

I just tested with my Demo App, and in my environment it has nothing to do with the ShowModal. If I just run the App and close the Main Form, I've got the same result as with the secondary form.

.-Tee-.

Tommi Prami

2011-09-27 08:35

reporter   ~0052210

Hello hello,

I've just finished tracking the revision that causes this bug.

Seems that it is related into some other bug fix:

Revision 31868 is OK and the this Bug appears in the revision 31869

The revision 31869 is the fix for the BUG : http://mantis.freepascal.org/view.php?id=19898 "0019898: [WinCE] Sometimes an access violation or a bus error occurs when creating a form with a menu"

Change is in the WinCEWSMenus.pp and the change is from :


class procedure TWinCEWSMenuItem.DestroyHandle(const AMenuItem: TMenuItem);
begin
  if Assigned(AMenuItem.Parent) then
    DeleteMenu(AMenuItem.Parent.Handle, AMenuItem.Command, MF_BYCOMMAND);
  DestroyMenu(AMenuItem.Handle);
  TriggerFormUpdate(AMenuItem);
end;

into :

class procedure TWinCEWSMenuItem.DestroyHandle(const AMenuItem: TMenuItem);
var
  idx: Integer;
begin
  // this is the top item of a menu, so we must undo TWinCEWSMenu.CreateHandle
  if AMenuItem = AMenuItem.Menu.Items then
  begin
    idx := MenuHandleList.IndexOf(Pointer(AMenuItem.Handle));
    if idx >= 0 then
    begin
      // the object is at the same position as the handle
      MenuHandleList.Delete(idx);
      MenuLCLObjectList.Delete(idx);
    end;
  end;

  if Assigned(AMenuItem.Parent) then
    DeleteMenu(AMenuItem.Parent.Handle, AMenuItem.Command, MF_BYCOMMAND);
  DestroyMenu(AMenuItem.Handle);
  TriggerFormUpdate(AMenuItem);
end;

The question now is what in my project and Attached Test project contain, which causes this change to Backfire. I have no idea. Maybe someone familiar with the code (generally) will see the problem in here.

Basically (my gut feeling) that it will prematurely will free something that it should not, when the menu is the way in here. The code above most likely will fix some other kind of menu-structure problem. And the fix just does not behave well with the other kind of situation. And this will lead into the Access Violations I see. OK, anyone can figure that out, but still, why is that happening, I must confess that I don't know the code well enough that I could even Guess?

.-Tee-.

Felipe Monteiro de Carvalho

2011-09-27 08:54

developer   ~0052212

Link to the mentioned revision

http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=31869

Felipe Monteiro de Carvalho

2011-09-27 09:01

developer   ~0052215

If you want to further debug the LCL your best bet is probably adding DebugLn calls to the beginnings of various routines which you consider important and see how the code flows through them. You can also use this to write variables values and other stuff ... there are already a lot of those in the LCL-Wince, just check how they work.

Felipe Monteiro de Carvalho

2011-09-28 10:50

developer   ~0052242

In rev32539 a applied a fix from Sven.

Is now your problem fixed?

Tommi Prami

2011-09-28 14:54

reporter   ~0052246

Hello hello,

Seems that it works now. At Least my text APP works...

Sweet...

.-Tee-.

Tommi Prami

2011-09-28 14:55

reporter   ~0052247

Hello hello,

Seems that it works now. At Least my test APP works... And in my environment...

Sweet...

.-Tee-.

Issue History

Date Modified Username Field Change
2011-08-12 14:40 Tommi Prami New Issue
2011-08-12 14:40 Tommi Prami File Added: MenuTest.zip
2011-08-12 14:40 Tommi Prami Widgetset => WinCE
2011-08-12 14:41 Felipe Monteiro de Carvalho Status new => assigned
2011-08-12 14:41 Felipe Monteiro de Carvalho Assigned To => Felipe Monteiro de Carvalho
2011-09-13 13:23 Felipe Monteiro de Carvalho Note Added: 0051775
2011-09-14 15:05 Felipe Monteiro de Carvalho Note Added: 0051813
2011-09-14 15:11 Felipe Monteiro de Carvalho LazTarget => -
2011-09-14 15:11 Felipe Monteiro de Carvalho Summary Exceptions while closing window with main menu on WinCE/Windows Mobile. => Crash while closing a modal window on WinCE
2011-09-15 11:06 Tommi Prami File Added: MenuTest_2.zip
2011-09-15 11:12 Tommi Prami Note Added: 0051848
2011-09-17 20:35 Zaher Dirkey Note Added: 0051956
2011-09-17 20:35 Zaher Dirkey File Added: MainMenuModalCrash.patch
2011-09-19 15:30 Tommi Prami Note Added: 0052028
2011-09-19 18:33 Tommi Prami Note Added: 0052034
2011-09-20 13:17 Tommi Prami Note Added: 0052062
2011-09-27 08:35 Tommi Prami Note Added: 0052210
2011-09-27 08:54 Felipe Monteiro de Carvalho Note Added: 0052212
2011-09-27 08:55 Felipe Monteiro de Carvalho Relationship added related to 0019898
2011-09-27 09:01 Felipe Monteiro de Carvalho Note Added: 0052215
2011-09-27 09:02 Felipe Monteiro de Carvalho Relationship added related to 0020029
2011-09-28 10:45 Felipe Monteiro de Carvalho Relationship added related to 0020274
2011-09-28 10:50 Felipe Monteiro de Carvalho Note Added: 0052242
2011-09-28 10:51 Felipe Monteiro de Carvalho Status assigned => feedback
2011-09-28 14:54 Tommi Prami Note Added: 0052246
2011-09-28 14:55 Tommi Prami Note Added: 0052247
2011-12-12 07:36 Felipe Monteiro de Carvalho Fixed in Revision => 32539
2011-12-12 07:36 Felipe Monteiro de Carvalho Status feedback => resolved
2011-12-12 07:36 Felipe Monteiro de Carvalho Fixed in Version => 0.9.31 (SVN)
2011-12-12 07:36 Felipe Monteiro de Carvalho Resolution open => fixed
2014-09-21 18:10 Juha Manninen Relationship added related to 0026757