View Issue Details

IDProjectCategoryView StatusLast Update
0032366LazarusWidgetsetpublic2018-08-28 20:07
ReporterPrzemyslaw Dmochowski Assigned ToStephano  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWinCEOSWinCE 
Product Version1.8RC4 
Summary0032366: TForm.ShowModal on WinCE loops itself
DescriptionWhen running a program with a form created in an onClick event and then shown as modal - application hangs in an infinite loop triggering onShow event.

It happens in WinCE widgetset, but not in Win32.

In 1.6.4 it was correct, error discovered also in 1.8RC3 (I did not test older RC's of 1.8)
Steps To Reproducetry to compile and run attached project.
Additional InformationI tried to change borderstyle from none to something else but it did not help.

Also in 1.6.4 it worked fine.
Tagswince
Fixed in Revision58432
LazTarget-
WidgetsetWinCE
Attached Files

Relationships

related to 0033571 resolvedStephano Program crash when use ShowModal 

Activities

Przemyslaw Dmochowski

2017-09-01 11:17

reporter  

Przemyslaw Dmochowski

2017-09-01 11:32

reporter  

Przemyslaw Dmochowski

2017-09-01 11:33

reporter   ~0102555

I removed unnecessary unit dependence from the test project.
I enclosed also compiled exe for reference.

For tests - please use newer archive: laz1.8.rc4_showmodal_err_wince.zip

LacaK

2018-06-25 11:45

developer   ~0109044

Last edited: 2018-06-25 11:46

View 2 revisions

Bug is still unresolved in 1.8.4 and also in 1.9 (trunk)

Severity is "major" or probably "blocker"

Bart Broersma

2018-06-25 12:25

developer   ~0109045

Someone with a WinCE device or emulator should bisect the guilty revision.

LacaK

2018-07-02 12:04

developer   ~0109182

Last edited: 2018-07-02 12:06

View 2 revisions

I can confirm, that loop occurs between TControl.EnableAutoSizing, where is called TControl.DoAllAutoSize, which calls again TControl.EnableAutoSizing.
I attach debug.log, may be it helps somebody experienced identify what happens.
(Form2, which is shown has two labels Label1, Label2)

LacaK

2018-07-02 12:04

developer  

lcldebug.log (56,339 bytes)

Juha Manninen

2018-07-02 12:58

developer   ~0109185

Please find the guilty revision and the bug can be analyzed better.

LacaK

2018-07-02 15:35

developer   ~0109190

Last edited: 2018-07-03 12:01

View 3 revisions

Guilty revision is 54722, where procedure TCustomForm.UpdateShowInTaskBar was modified (due to bug 0031248).
Please note also differences in implementation of SetShowInTaskbar in widgetsets Win32 and WinCE.

LacaK

2018-07-03 12:36

developer  

wincewsforms.pp.diff (1,352 bytes)   
--- wincewsforms.pp.old	Sun Mar 13 23:28:24 2016
+++ wincewsforms.pp	Tue Jul 03 12:09:09 2018
@@ -405,13 +405,37 @@
 
 class procedure TWinCEWSCustomForm.SetShowInTaskbar(const AForm: TCustomForm;
   const AValue: TShowInTaskbar);
+var
+  OldStyle, NewStyle: DWord;
+  Visible, Active: Boolean;
 begin
   if not WSCheckHandleAllocated(AForm, 'SetShowInTaskbar') then
     Exit;
   if (Application <> nil) and (AForm = Application.MainForm) then
     Exit;
 
-  RecreateWnd(AForm);
+  OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE);
+  if AValue = stAlways then
+    NewStyle := OldStyle or WS_EX_APPWINDOW
+  else
+    NewStyle := OldStyle and not WS_EX_APPWINDOW;
+  if OldStyle = NewStyle then Exit;
+
+  // to apply this changes we need either to hide window or recreate it. Hide is
+  // less difficult
+  Visible := IsWindowVisible(AForm.Handle);
+  Active := GetForegroundWindow = AForm.Handle;
+  if Visible then
+    ShowWindow(AForm.Handle, SW_HIDE);
+
+  SetWindowLong(AForm.Handle, GWL_EXSTYLE, NewStyle);
+
+  // now we need to restore window visibility with saving focus
+  if Visible then
+    if Active then
+      ShowWindow(AForm.Handle, SW_SHOW)
+    else
+      ShowWindow(AForm.Handle, SW_SHOWNA);
 end;
 
 class procedure TWinCEWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
wincewsforms.pp.diff (1,352 bytes)   

LacaK

2018-07-03 12:48

developer   ~0109202

Last edited: 2018-07-03 13:08

View 4 revisions

I have attached patch for WinCE, which prevents cycling. It is taken from Win32 widgetset.
(I have attached also patch for Win32, which removes unneded line)

There is one minor problem, that second opened window is positioned slightly out-of screen when Position=poScreenCenter or poMainFormCenter

LacaK

2018-07-03 12:55

developer  

win32wsforms.pp.diff (577 bytes)   
--- win32wsforms.pp.old	Tue Jul 03 11:32:13 2018
+++ win32wsforms.pp	Tue Jul 03 12:47:52 2018
@@ -676,11 +676,10 @@
     Exit;
 
   OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE);
-  NewStyle := OldStyle;
   if AValue = stAlways then
-    NewStyle := NewStyle or WS_EX_APPWINDOW
+    NewStyle := OldStyle or WS_EX_APPWINDOW
   else
-    NewStyle := NewStyle and not WS_EX_APPWINDOW;
+    NewStyle := OldStyle and not WS_EX_APPWINDOW;
   if OldStyle = NewStyle then exit;
 
   // to apply this changes we need either to hide window or recreate it. Hide is
win32wsforms.pp.diff (577 bytes)   

Juha Manninen

2018-07-03 14:44

developer   ~0109204

I applied the Win32 patch in r58431. Thanks.
Stephano has enough rights to commit the WinCE patch, if it proves to be good.

LacaK, please create patches from the root directory of Lazarus sources. They will be easier to apply.
Also, you should create patches against Lazarus trunk because that's where they will be applied. Now it succeeded with an offset:
 Hunk 0000001 succeeded at 682 (offset 6 lines).

LacaK

2018-07-03 15:27

developer   ~0109205

@Juha: Thank you. Yes I understand.

Stephano

2018-07-03 16:01

developer   ~0109206

@Lacak, as Juha mentioned, pls always create patches relative to the top lazarus folder.

WinCE and Win32 widgetset SetShowInTaskbar diverged in commits 20707 and 20710. If rev 54722 is the cuplrit, then it means that, previous to this revision, SetShowInTaskbar wasn't getting called in a way to create the loop.

Patch applied. Thanks!
Pls test and close if OK.

Issue History

Date Modified Username Field Change
2017-09-01 11:17 Przemyslaw Dmochowski New Issue
2017-09-01 11:17 Przemyslaw Dmochowski File Added: laz1.8.rc4_showmodal_err.zip
2017-09-01 11:32 Przemyslaw Dmochowski File Added: laz1.8.rc4_showmodal_err_wince.zip
2017-09-01 11:33 Przemyslaw Dmochowski Note Added: 0102555
2018-06-25 11:45 LacaK Note Added: 0109044
2018-06-25 11:46 LacaK Note Edited: 0109044 View Revisions
2018-06-25 12:25 Bart Broersma Note Added: 0109045
2018-06-29 18:45 Stephano Assigned To => Stephano
2018-06-29 18:45 Stephano Status new => assigned
2018-06-29 20:51 Juha Manninen Relationship added related to 0033571
2018-07-02 12:04 LacaK Note Added: 0109182
2018-07-02 12:04 LacaK File Added: lcldebug.log
2018-07-02 12:06 LacaK Note Edited: 0109182 View Revisions
2018-07-02 12:58 Juha Manninen Note Added: 0109185
2018-07-02 15:35 LacaK Note Added: 0109190
2018-07-03 11:56 LacaK Note Edited: 0109190 View Revisions
2018-07-03 12:01 LacaK Note Edited: 0109190 View Revisions
2018-07-03 12:36 LacaK File Added: wincewsforms.pp.diff
2018-07-03 12:48 LacaK Note Added: 0109202
2018-07-03 12:55 LacaK File Added: win32wsforms.pp.diff
2018-07-03 12:55 LacaK Note Edited: 0109202 View Revisions
2018-07-03 13:04 LacaK Note Edited: 0109202 View Revisions
2018-07-03 13:08 LacaK Note Edited: 0109202 View Revisions
2018-07-03 14:44 Juha Manninen Note Added: 0109204
2018-07-03 15:27 LacaK Note Added: 0109205
2018-07-03 16:01 Stephano Note Added: 0109206
2018-07-03 16:01 Stephano Fixed in Revision => 58432
2018-07-03 16:01 Stephano LazTarget => -
2018-07-03 16:01 Stephano Status assigned => resolved
2018-07-03 16:01 Stephano Resolution open => fixed
2018-08-28 20:07 LacaK Tag Attached: wince