View Issue Details

IDProjectCategoryView StatusLast Update
0027577LazarusIDEpublic2015-03-04 19:37
ReporterDenis GolovanAssigned ToZeljan Rikalo 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.5 (SVN)Product Build 
Target Version1.4Fixed in Version1.5 (SVN) 
Summary0027577: All modal IDE windows crash on closing
DescriptionHi

For a long time I had been experiencing a nasty bug in Lazarus.
It was a segfault when closing any modal window in Lazarus ("Evaluate/Modify" dialog mostly) under GTK2 interface.

I traced it down to dangling pointer within gtk2 interface.
See attachments for a workaround, gdb trace log and gdb script to reproduce trace log if necessary.

Please fix it properly.
TagsNo tags attached.
Fixed in Revision48136
LazTarget1.4
WidgetsetGTK 2
Attached Files
  • crash_fix.patch (529 bytes)
    diff --git a/lcl/interfaces/gtk2/gtk2callback.inc b/lcl/interfaces/gtk2/gtk2callback.inc
    index 8cb1a55..b0b4ccf 100644
    --- a/lcl/interfaces/gtk2/gtk2callback.inc
    +++ b/lcl/interfaces/gtk2/gtk2callback.inc
    @@ -1140,7 +1140,7 @@ begin
       // issues #18164,#21897,#23182
       if GtkWidgetIsA(Widget, gtk_type_entry) then
       begin
    -    g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
    +    //g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
         //save now CursorPos and SelStart in WidgetInfo
         if (Widget <> nil) then
         begin
    
    crash_fix.patch (529 bytes)
  • lazarus-script2 (102 bytes)
    set logging file gdb.txt
    set logging on
    break GTK_IS_WIDGET
    command 1
    backtrace full
    continue
    end
    run
    
    lazarus-script2 (102 bytes)
  • gdb.txt.gz (88,004 bytes)
  • gtk2editidletimercrash.diff (1,452 bytes)
    Index: lcl/interfaces/gtk2/gtk2callback.inc
    ===================================================================
    --- lcl/interfaces/gtk2/gtk2callback.inc	(revision 48093)
    +++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
    @@ -1103,6 +1103,7 @@
       Mess : TLMessage;
       Info: PWidgetInfo;
       AStart,AEnd: gint;
    +  AForm: TCustomForm;
     {$IFDEF VerboseFocus}
       LCLObject: TObject;
       CurFocusWidget: PGtkWidget;
    @@ -1138,8 +1139,23 @@
     
       // do not show selection when widget is unfocused
       // issues #18164,#21897,#23182
    -  if GtkWidgetIsA(Widget, gtk_type_entry) then
    +  if GtkWidgetIsA(Widget, gtk_type_entry) and Assigned(Data) then
       begin
    +    if (csDestroying in TComponent(Data).ComponentState) or
    +      (csDestroyingHandle in TControl(Data).ControlState) then
    +    begin
    +      DebugLn('NOTICE: Control is destroying itself, do not add new idle timer for ',dbgsName(TControl(Data)));
    +      exit;
    +    end;
    +    AForm := GetParentForm(TControl(Data));
    +    if Assigned(AForm) and ((csDestroying in AForm.ComponentState) or
    +      (csDestroyingHandle in AForm.ControlState) or
    +      ((fsModal in AForm.FormState) and (AForm.ModalResult <> mrNone)) ) then
    +    begin
    +      DebugLn('NOTICE: Parent form is destroying, do not add new idle timer for ',dbgsName(TControl(Data)));
    +      exit;
    +    end;
    +
         g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
         //save now CursorPos and SelStart in WidgetInfo
         if (Widget <> nil) then
    

Relationships

has duplicate 0029775 resolvedBart Broersma Crash on processing enter with a default button 
related to 0026752 closedZeljan Rikalo Evaluate/Modify dialog crashes on closing 

Activities

Denis Golovan

2015-03-01 12:32

reporter  

crash_fix.patch (529 bytes)
diff --git a/lcl/interfaces/gtk2/gtk2callback.inc b/lcl/interfaces/gtk2/gtk2callback.inc
index 8cb1a55..b0b4ccf 100644
--- a/lcl/interfaces/gtk2/gtk2callback.inc
+++ b/lcl/interfaces/gtk2/gtk2callback.inc
@@ -1140,7 +1140,7 @@ begin
   // issues #18164,#21897,#23182
   if GtkWidgetIsA(Widget, gtk_type_entry) then
   begin
-    g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
+    //g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
     //save now CursorPos and SelStart in WidgetInfo
     if (Widget <> nil) then
     begin
crash_fix.patch (529 bytes)

Denis Golovan

2015-03-01 12:33

reporter  

lazarus-script2 (102 bytes)
set logging file gdb.txt
set logging on
break GTK_IS_WIDGET
command 1
backtrace full
continue
end
run
lazarus-script2 (102 bytes)

Denis Golovan

2015-03-01 12:33

reporter  

gdb.txt.gz (88,004 bytes)

Denis Golovan

2015-03-01 12:48

reporter   ~0081532

Forgot to mention.
I've tested using Lazarus svn rev.48053 under Linux x64

Zeljan Rikalo

2015-03-01 17:18

developer   ~0081542

Your patch will open some old bugs.

Zeljan Rikalo

2015-03-01 17:30

developer   ~0081544

Cannot reproduce on 32bit system.

Denis Golovan

2015-03-01 19:29

reporter   ~0081547

Same bug appeared on 32bit Linux system.
I suspect there is something related to gtk version + some timing.

And yes, I know it's not a proper fix. That's why I call it the workaround.

Zeljan Rikalo

2015-03-02 18:25

developer  

gtk2editidletimercrash.diff (1,452 bytes)
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revision 48093)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
@@ -1103,6 +1103,7 @@
   Mess : TLMessage;
   Info: PWidgetInfo;
   AStart,AEnd: gint;
+  AForm: TCustomForm;
 {$IFDEF VerboseFocus}
   LCLObject: TObject;
   CurFocusWidget: PGtkWidget;
@@ -1138,8 +1139,23 @@
 
   // do not show selection when widget is unfocused
   // issues #18164,#21897,#23182
-  if GtkWidgetIsA(Widget, gtk_type_entry) then
+  if GtkWidgetIsA(Widget, gtk_type_entry) and Assigned(Data) then
   begin
+    if (csDestroying in TComponent(Data).ComponentState) or
+      (csDestroyingHandle in TControl(Data).ControlState) then
+    begin
+      DebugLn('NOTICE: Control is destroying itself, do not add new idle timer for ',dbgsName(TControl(Data)));
+      exit;
+    end;
+    AForm := GetParentForm(TControl(Data));
+    if Assigned(AForm) and ((csDestroying in AForm.ComponentState) or
+      (csDestroyingHandle in AForm.ControlState) or
+      ((fsModal in AForm.FormState) and (AForm.ModalResult <> mrNone)) ) then
+    begin
+      DebugLn('NOTICE: Parent form is destroying, do not add new idle timer for ',dbgsName(TControl(Data)));
+      exit;
+    end;
+
     g_idle_add(@GtkEntryDelayClearCursorPos, Widget);
     //save now CursorPos and SelStart in WidgetInfo
     if (Widget <> nil) then

Zeljan Rikalo

2015-03-02 18:26

developer   ~0081563

Please test with attached patch. Patch is created on Mint 16 64bit and there's no crashes anymore (see NOTICE messages from patch in console).

Denis Golovan

2015-03-02 20:10

reporter   ~0081573

Yes. Now it works fine.
But I still get some assertions(?) emitted on console.
See below.

NOTICE: Control is destroying itself, do not add new idle timer for cmbExpression:TComboBox

(lazarus:10108): GLib-CRITICAL **: Source ID 1140 was not found when attempting to remove it
(lazarus:10108): GLib-CRITICAL **: Source ID 1139 was not found when attempting to remove it

Zeljan Rikalo

2015-03-03 08:40

developer   ~0081585

Messages from glib are not related to this bug.

Zeljan Rikalo

2015-03-03 11:37

developer   ~0081590

Just checked: I've covered all g_idle_add() by debugLn and looking into result of added timer. All timers are ok, such assert is not related to our g_idle_add(), probably something from glib or gtk2.

Denis Golovan

2015-03-03 21:03

reporter   ~0081614

Ok. Let's fix at least this bug :)

Zeljan Rikalo

2015-03-04 11:41

developer   ~0081624

Issue 26752 is also fixed with this patch ?

Denis Golovan

2015-03-04 17:27

reporter   ~0081639

Yes.

Zeljan Rikalo

2015-03-04 17:40

developer   ~0081640

Please test and close if ok.

Denis Golovan

2015-03-04 19:37

reporter   ~0081642

Thanks. Works now.

Issue History

Date Modified Username Field Change
2015-03-01 12:32 Denis Golovan New Issue
2015-03-01 12:32 Denis Golovan File Added: crash_fix.patch
2015-03-01 12:33 Denis Golovan File Added: lazarus-script2
2015-03-01 12:33 Denis Golovan File Added: gdb.txt.gz
2015-03-01 12:48 Denis Golovan Note Added: 0081532
2015-03-01 12:51 Mattias Gaertner Assigned To => Zeljan Rikalo
2015-03-01 12:51 Mattias Gaertner Status new => assigned
2015-03-01 17:15 Juha Manninen Relationship added related to 0026752
2015-03-01 17:18 Zeljan Rikalo Note Added: 0081542
2015-03-01 17:30 Zeljan Rikalo Note Added: 0081544
2015-03-01 19:29 Denis Golovan Note Added: 0081547
2015-03-02 18:25 Zeljan Rikalo File Added: gtk2editidletimercrash.diff
2015-03-02 18:26 Zeljan Rikalo LazTarget => -
2015-03-02 18:26 Zeljan Rikalo Note Added: 0081563
2015-03-02 18:26 Zeljan Rikalo Status assigned => feedback
2015-03-02 20:10 Denis Golovan Note Added: 0081573
2015-03-02 20:10 Denis Golovan Status feedback => assigned
2015-03-03 08:40 Zeljan Rikalo Note Added: 0081585
2015-03-03 11:37 Zeljan Rikalo Note Added: 0081590
2015-03-03 21:03 Denis Golovan Note Added: 0081614
2015-03-04 11:41 Zeljan Rikalo Note Added: 0081624
2015-03-04 11:41 Zeljan Rikalo Status assigned => feedback
2015-03-04 17:27 Denis Golovan Note Added: 0081639
2015-03-04 17:27 Denis Golovan Status feedback => assigned
2015-03-04 17:40 Zeljan Rikalo Fixed in Revision => 48136
2015-03-04 17:40 Zeljan Rikalo Note Added: 0081640
2015-03-04 17:40 Zeljan Rikalo Status assigned => resolved
2015-03-04 17:40 Zeljan Rikalo Resolution open => fixed
2015-03-04 17:41 Zeljan Rikalo LazTarget - => 1.4
2015-03-04 17:41 Zeljan Rikalo Fixed in Version => 1.5 (SVN)
2015-03-04 17:41 Zeljan Rikalo Target Version => 1.4
2015-03-04 19:37 Denis Golovan Note Added: 0081642
2015-03-04 19:37 Denis Golovan Status resolved => closed
2016-03-04 18:20 Bart Broersma Relationship added has duplicate 0029775