Questions about call stack in grids.pas lazarus / 31-LCL ---------------------------------------------------------------------- tintinux · 2018-12-26 10:18 Hi I'm trying to find a bug encountered using the TCustomStringGrid component. Starting with a TCustomStringGrid having 2 rows and 2 columns, my application display a text in Cells [1,1]. During this operation, there is sometimes an attempt to get the value of Cells[1,2] which doesn't exist, and obviously this raises an exception. Previously the grid had 3 rows, but the 3rd one was removed (using DeleteRowCol) before I try to display in Cells[1,1].  I suspect something not properly cleared in relation to Row 2, but don't find anything. The call stack is : 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 #0 fpc_raiseexception at :0#1 GETCELLS(0x11ed2b50, 1, 2) at grids.pas:9894#2 GETCELLS(0x11e46670, 1, 2) at grids.pas:10888#3 SETEDITTEXT(0x11e46670, 1, 2, 0xa017218 '6,00') at grids.pas:11424#4 EDITORTEXTCHANGED(0x11e46670, 1, 2, 0xa017218 '6,00') at grids.pas:8337#5 CHANGE(0x11e480b0) at grids.pas:10142#6 TEXTCHANGED(0x11e480b0) at include\customedit.inc:644#7 TEXTCHANGED(0x11e480b0) at maskedit.pp:1604#8 CMTEXTCHANGED(0x11e480b0, {MSG = 45074, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, WPARAMFILLER = {FILLER = {0, 0, 0, 0}}, LPARAMLO = 0, LPARAMHI = 0, LPARAMFILLER = {FILLER = {0, 0, 0, 0}}, RESULTLO = 0, RESULTHI = 0, RESULTFILLER = {FILLER = {0, 0, 0, 0}}}) at include\control.inc:1203#9 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal at :0#10 ?? at :0#11 WNDPROC(0x11e480b0, {MSG = 45074, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, WPARAMFILLER = {FILLER = {0, 0, 0, 0}}, LPARAMLO = 0, LPARAMHI = 0, LPARAMFILLER = {FILLER = {0, 0, 0, 0}}, RESULTLO = 0, RESULTHI = 0, RESULTFILLER = {FILLER = {0, 0, 0, 0}}}) at include\wincontrol.inc:5425#12 WNDPROC(0x11e480b0, {MSG = 45074, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, WPARAMFILLER = {FILLER = {0, 0, 0, 0}}, LPARAMLO = 0, LPARAMHI = 0, LPARAMFILLER = {FILLER = {0, 0, 0, 0}}, RESULTLO = 0, RESULTHI = 0, RESULTFILLER = {FILLER = {0, 0, 0, 0}}}) at include\customedit.inc:528#13 WNDPROC(0x11e480b0, {MSG = 45074, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, WPARAMFILLER = {FILLER = {0, 0, 0, 0}}, LPARAMLO = 0, LPARAMHI = 0, LPARAMFILLER = {FILLER = {0, 0, 0, 0}}, RESULTLO = 0, RESULTHI = 0, RESULTFILLER = {FILLER = {0, 0, 0, 0}}}) at grids.pas:10132#14 PERFORM(0x11e480b0, 45074, 0, 0) at include\control.inc:1581#15 REALSETTEXT(0x11e480b0, 0xa017218 '6,00') at include\control.inc:5030#16 REALSETTEXT(0x11e480b0, 0xa017218 '6,00') at include\wincontrol.inc:8354#17 REALSETTEXT(0x11e480b0, 0xa017218 '6,00') at include\customedit.inc:569#18 REALSETTEXT(0x11e480b0, 0xa017218 '6,00') at maskedit.pp:1077#19 SETTEXT(0x11e480b0, 0xa017218 '6,00') at include\control.inc:5055#20 MSG_SETVALUE(0x11e480b0, {LCLMSG = {MSG = 66859, WPARAM = 1, LPARAM = 1, RESULT = 9, WPARAMLO = 1, WPARAMHI = 0, WPARAMFILLER = {FILLER = {0, 0, 0, 0}}, LPARAMLO = 1, LPARAMHI = 0, LPARAMFILLER = {FILLER = {0, 0, 0, 0}}, RESULTLO = 9, RESULTHI = 0, RESULTFILLER = {FILLER = {0, 0, 0, 0}}}, GRID = 0x11e46670, COL = 1, ROW = 1, VALUE = 0xa017218 '6,00', CELLRECT = {LEFT = 144042720, TOP = 0, RIGHT = 144042640, BOTTOM = 0, TOPLEFT = {X = 144042720, Y = 0}, BOTTOMRIGHT = {X = 144042640, Y = 0}, VECTOR = {144042720, 0, 144042640, 0}}, OPTIONS = 167568708}) at grids.pas:10244#21 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal at :0#22 ?? at :0#23 GETEDITTEXT(0x895ea90, 300181104, 167568708) at grids.pas:11311#24 UPDATECELL(0x895eae0) at grids.pas:10941#25 SETCELLS(0x11e46670, 1, 1, 0xa011a98 '6,00') at grids.pas:10953 The source (2.0.0-RC2, revision 59373) is : 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 TCustomStringGrid.SetCells(ACol, ARow: Integer; const AValue: string);  procedure UpdateCell;  begin    if EditorMode and (aCol=FCol)and(aRow=FRow) and      not (gfEditorUpdateLock in GridFlags) then    begin      EditorDoSetValue;    end;    InvalidateCell(aCol, aRow);  end;var  C: PCellProps;begin  C:= FGrid.Celda[aCol,aRow];  if C<>nil then begin    if C^.Text<>nil then      StrDispose(C^.Text);    C^.Text:=StrNew(pchar(aValue));    UpdateCell;    FModified := True;  end else begin    if AValue<>'' then begin      New(C);      C^.Text:=StrNew(pchar(Avalue));      C^.Attr:=nil;      C^.Data:=nil;      FGrid.Celda[aCol,aRow]:=C;      UpdateCell;      FModified := True;    end;  end;end; Reading the source, In line 10941, there is a call to EditorDoSetValue. My questions are :   - why is there no line in the stack for the call to EditorDoSetValue   - what is meaning "?? at :0" after the call to GetEditText. in #22   - Is there a compilation option to show exactly the called routines ?   - How or where can I see the exact reason why the stack ends with GETCELLS(0x11ed2b50, 1, 2) Currently my Compilation options are starting with : 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 -MObjFPC- Scahi-Cirot-gs-gl-WG-l-vewnhibq-vm5024 (I haven't listed the -F ) Thanks for help ! ---------------------------------------------------------------------- Ñuño_Martínez · 2018-12-26 11:31 Quote from: tintinux on December 26, 2018, 11:18:47 am  - why is there no line in the stack for the call to EditorDoSetValue Not sure but may be EditorDoSetValue is INLINE.  Should see the declaration though. Quote from: tintinux on December 26, 2018, 11:18:47 am  - what is meaning "?? at :0" after the call to GetEditText. in #22 The "??" means that the debugger doesn't has information enough to identify the procedure/funcion/routine.   This happens with the RTL or calls to the operating system or any other library compiled without debug information. Quote from: tintinux on December 26, 2018, 11:18:47 am  - Is there a compilation option to show exactly the called routines ? Standar debug options should be enough. Quote from: tintinux on December 26, 2018, 11:18:47 am  - How or where can I see the exact reason why the stack ends with GETCELLS(0x11ed2b50, 1, 2) GETCELLS is in the top of the stack.  That's all. "#0 fpc_raiseexception at :0" means the exception was raised (or re- raised) by the RTL and the compiler doesn't has information enough to identify the origin. ---------------------------------------------------------------------- Martin_fr · 2018-12-26 11:44 Sometimes functions (kernel or rtl) like _DISPATCH are compiled without "stackframe" Then the debugger can not read the stack around them. What happens is, that they hide the next caller from the stack. So you then miss one line. ---------------------------------------------------------------------- jamie · 2018-12-26 20:49 could it be possible the EDITOR was enabled on a cell when this happened ? ---------------------------------------------------------------------- tintinux · 2018-12-27 08:07 Quote from: jamiecould it be possible the EDITOR was enabled on a cell when this happened ?Yes, I think it is the cause of the issue. A cell is edited in row 2, then the row 2 is deleted, and when something is later written in the Row 1 there is an attempt to get the value of the previously edited cell in Row 2. As a workaround, I have tried unsuccesfully to disable the editor and to process messages, before deleting row. Maybe there is a temporary solution like that, but this should be better fixed at the component level. Unfortunately, I can't reproduce the issue in a simple sample application. I can only reproduce at will in Gestinux. However, I believe that the call stack shows that the calling application is not responsible. But I don't find anything, by reading the call stack and the source. Any hints appreciated ! ---------------------------------------------------------------------- tintinux · 2018-12-27 08:40 This is the debuglog  (with debug lines added in Grids.pas before DeleteColRow, and before raising exception). We see that Rows 2 and 1 are deleted, and then TStringCellEditor.Change INIT text=6,00 is called with wrong coordinates (Row=2). Code: [Select]DeleteColRow(IsColumn:=False; index := 2); Grid.EditorSetMode=False INIT Grid.EditorSetMode END Grid.EditorSetMode=False INIT Grid.EditorSetMode END DeleteColRow(IsColumn:=False; index := 1); Grid.EditorSetMode=False INIT Grid.EditorSetMode END Grid.EditorSetMode=False INIT Grid.EditorSetMode END Grid.EditorPos INIT Grid.EditorPos END TStringCellEditor.Change INIT text=6,00 ***Index Out of range Cell[Col=1 Row=2] ---------------------------------------------------------------------- wp · 2018-12-27 09:32 Are there any event handlers attached to the grid? If yes, remove them and see if the issue still exists. I'd activate debug information for all used units by adding a sorresponding custom option such as -gw2 to "Additions and overrides" of the project options, set a break point on the line which deletes the row and step through the code and into the LCL units. ---------------------------------------------------------------------- tintinux · 2018-12-27 10:19 QuoteAre there any event handlers attached to the grid?I have already tried to remove them and the issue still exists. QuoteI'd activate debug information for all used units by adding a sorresponding custom option such as -gw2 to "Additions and overrides" of the project options, set a break point on the line which deletes the row and step through the code and into the LCL units. I tried and noticed that 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 EditorMode:=False; is executed at a time, but it looks like it is not enough. I suppose there is an message sent before the delete by TStringCellEditor, remaining in queue, and processed after the delete, when the application has created another row 1 and writes something in it.  I don't know how I can catch or purge it... ---------------------------------------------------------------------- tintinux · 2018-12-27 10:34 This is the log with GridTraceMsg : Code: [Select]DoubleClick INIT GRID: [00000014] W=FFFFFFFFC701182F L=00000000 LM_ERASEBKGND GRID: [00000014] W=FFFFFFFFC701182F L=00000000 LM_ERASEBKGND GRID: [0000000F] W=FFFFFFFFC701182F L=013FE1A8 LM_PAINT DeleteColRow(IsColumn:=False; index := 2); Grid.EditorSetMode=False INIT Grid.EditorSetMode END Grid.EditorSetMode=False INIT Grid.EditorSetMode END DeleteColRow(IsColumn:=False; index := 1); Grid.EditorSetMode=False INIT Grid.EditorSetMode END Grid.EditorSetMode=False INIT Grid.EditorSetMode END Grid.EditorPos INIT Grid.EditorPos END StrCellEditor: [0000B012] W=00000000 L=00000000 CM_TEXTCHANGED TStringCellEditor.Change INIT text='6,00' FCol=1 FRow=2 StrCellEditor: [0000B037] W=00000000 L=0A1E92E0 CM_BASE + 55 GRID: [0000B037] W=00000000 L=0A1E92E0 CM_BASE + 55 ***Index Out of range Cell[Col=1 Row=2] But it don't help me... ---------------------------------------------------------------------- wp · 2018-12-27 11:06 In the first post of this thread you are talking of a "TGrid" component, but there is not TGrid within the LCL. In your gestinux application, there is a TGGrid. This confuses me... Please specify the TCustomStringGrid descendant for which the bug happens. ---------------------------------------------------------------------- tintinux · 2018-12-27 12:00 Ah sorry, I'll modify. The problem is with TCustomStringGrid. TGGrid is just a descendant of TCustomStringGrid similar to TStringGrid with some additional properties and methods, and some other not published. ---------------------------------------------------------------------- jamie · 2018-12-27 20:45 Prior to using the DeleteColRow try doing this EditorMode := False; Application.ProcessMessages ---------------------------------------------------------------------- tintinux · 2018-12-29 09:12 Thanks, i have already tried that, unsuccesfully. In the code of TCustomStringGrid and in the log, you can see also that EditorMode := False; is executed, but not with Application.Processmessages. ---------------------------------------------------------------------- jamie · 2018-12-29 13:50 I have tested the TStringGrid many times and have never run into that issue yet. You said the component you are using is a descendant of the TCustumStringGrid.  Since we know the TstringGrid at this point seems to work I would suggest there is something going wrong with the control you are using.  Is it possible you could experiment with the optimizer level, try another level other than -02 because I have been seeing some complaints about coding not working properly at that level. ---------------------------------------------------------------------- tintinux · 2019-01-22 14:22 Hi I have submitted a bug with a sample program to reproduce it, using only TStringGrid component. Best regards