Recent

Author Topic: When select a new value in combobox raise exception  (Read 2131 times)

Tebo Software

  • New Member
  • *
  • Posts: 31
When select a new value in combobox raise exception
« on: September 30, 2020, 01:31:16 pm »
Hi guys

I'm using Lazarus 2.0.10 and I have a combobox with 2 items. When I select one, in runtime, all occurs right, but when I try to change the value a exception is raised:

Project XXXX raised exception class 'External: SIGSEGV'.

 In file 'laz_avl_tree.pp' at line 519

Someone know how to correted this?

thanks

Tebo Software

  • New Member
  • *
  • Posts: 31
Re: When select a new value in combobox raise exception
« Reply #1 on: September 30, 2020, 01:56:20 pm »
I was doing some tests and I noticed that in reality it is not the combobox, but when the EditMask of the MaskEdit component is changed.
It doesn't happen all the time.
If I comment on the EditMask exchange (lines 5 and 11), the error does not happen.

Code: Pascal  [Select][+][-]
  1. procedure TfrmCadPessoa.cbxTipoPessoaChange(Sender: TObject);
  2. begin
  3.   if cbxTipoPessoa.ItemIndex = 0 then
  4.   begin
  5.     edtDocumentoFiscal.EditMask := '999\.999\.999\-99;0;_';
  6.     lblDocumento.Caption := 'RG:';
  7.     lblDocumentoFiscal.Caption := 'CPF:';
  8.   end
  9.   else
  10.   begin
  11.     edtDocumentoFiscal.EditMask := '99\.999\.999\/9999\-99;0;_';
  12.     lblDocumento.Caption := 'Inscrição Estadual:';
  13.     lblDocumentoFiscal.Caption := 'CNPJ:';
  14.   end;
  15. end;  

Tebo Software

  • New Member
  • *
  • Posts: 31
Re: When select a new value in combobox raise exception
« Reply #2 on: September 30, 2020, 02:45:04 pm »
I attached an image of the Call Stack

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: When select a new value in combobox raise exception
« Reply #3 on: September 30, 2020, 03:05:41 pm »
I did only a simple test and changing EditMask of MaskEdit does not crash in GTK2 nor Qt4.
Can you try the latest trunk? And test with Qt?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: When select a new value in combobox raise exception
« Reply #4 on: September 30, 2020, 08:20:06 pm »
Your call stack does not show any MaskEdit. Instead it shows a crash in laz_avl_tree.
Can you reproduce the crash always systematically?
We would need a test application that reproduces it.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: When select a new value in combobox raise exception
« Reply #5 on: September 30, 2020, 11:40:11 pm »
I was doing some tests and I noticed that in reality it is not the combobox, but when the EditMask of the MaskEdit component is changed.
It doesn't happen all the time.
If I comment on the EditMask exchange (lines 5 and 11), the error does not happen.

Code: Pascal  [Select][+][-]
  1. procedure TfrmCadPessoa.cbxTipoPessoaChange(Sender: TObject);
  2. begin
  3.   if cbxTipoPessoa.ItemIndex = 0 then
  4.   begin
  5.     edtDocumentoFiscal.EditMask := '999\.999\.999\-99;0;_';
  6.     lblDocumento.Caption := 'RG:';
  7.     lblDocumentoFiscal.Caption := 'CPF:';
  8.   end
  9.   else
  10.   begin
  11.     edtDocumentoFiscal.EditMask := '99\.999\.999\/9999\-99;0;_';
  12.     lblDocumento.Caption := 'Inscrição Estadual:';
  13.     lblDocumentoFiscal.Caption := 'CNPJ:';
  14.   end;
  15. end;  

Just a helpful tip, If there is no selection in a ComboBox the index value will be -1 so be sure you are testing for this before using it as a value.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: When select a new value in combobox raise exception
« Reply #6 on: October 01, 2020, 12:09:03 am »
Go to "Project" > "Options" > "Additions and Overrides". Click in line "Stored in session of project". Click "Add" > "Custom option". Click into the new line "Custom", type "-gw2" (without the quotes). "OK".

Now when you compile your project all the required units, also those of the LCL (but not of RTL and FCL), are recompiled with debug information - this takes a bit longer than usual. When the program crashes you see line information in the stack trace. This way you can tell which routines were called before those in the crashing laz_avl_tree.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: When select a new value in combobox raise exception
« Reply #7 on: October 01, 2020, 10:30:10 am »
... When the program crashes you see line information in the stack trace. This way you can tell which routines were called before those in the crashing laz_avl_tree.
He already showed the call stack with proper debug info. The calls come from LCL-GTK2 code. I would love to have a way to reproduce the crash. Earlier I have suspected there is something wrong with laz_avl_tree.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Tebo Software

  • New Member
  • *
  • Posts: 31
Re: When select a new value in combobox raise exception
« Reply #8 on: October 05, 2020, 01:40:06 pm »
Good Morning
I have attached a working example.
To simulate the error just switch to the combobox cbxTipoPessoa a few times and it will give the error in Lazarus.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: When select a new value in combobox raise exception
« Reply #9 on: October 05, 2020, 01:53:50 pm »
I can reproduce the error, tested on Lazarus 2.0.10 Linux GTK2.

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: When select a new value in combobox raise exception
« Reply #10 on: October 05, 2020, 02:14:10 pm »
I experienced similar errors when closing forms. Following example is a simplest form.
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     Button1: TButton;
  4.     Edit1: TEdit;
  5.     Memo1: TMemo;
  6.     ValueListEditor1: TValueListEditor;
  7.     procedure Button1Click(Sender: TObject);
  8.     procedure FormClick(Sender: TObject);
  9.     procedure FormCreate(Sender: TObject);
  10.     procedure FormDestroy(Sender: TObject);
  11.     procedure ValueListEditor1EditingDone(Sender: TObject);
  12.     procedure ValueListEditor1Enter(Sender: TObject);
  13.     procedure ValueListEditor1Exit(Sender: TObject);
  14.   private
  15.     AStrLst: TStringList;
  16.  
  17.   public
  18.  
  19.   end;
  20.  
  21. implementation
  22.  
  23. procedure TForm1.FormCreate(Sender: TObject);
  24. begin
  25.   AStrLst := TStringList.Create;
  26. end;
  27.  
  28. procedure TForm1.FormDestroy(Sender: TObject);
  29. begin
  30.   AStrLst.Free;
  31. end;
  32.  
  33. procedure TForm1.ValueListEditor1EditingDone(Sender: TObject);
  34. begin
  35.    if Assigned(AStrLst) then
  36.        AStrLst.Text := ValuelistEditor1.Strings.Text;  // <-- Error happens here, when closing form
  37. end;
  38.  

This is quite simple. Any change done in the ValueListEditor is saved to the AStrLst.  Error occurs when I close the form, at the line I commented.

One possible cause, I guess, is related with the order of occurrence of event handlers. If the ValueListEditor1EditingDone is called after ValueListEditor1 is freed, then there should be SIGSEGV error. I'm thinking of this because I suffered problems from the order of event handlers,  especially with TListView. For example, when I click TListView while the focus in TEdit, TListView's OnSelect is first called, then TListView's OnEnter is called, and then TEdit's OnExit is called. 

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: When select a new value in combobox raise exception
« Reply #11 on: October 05, 2020, 02:31:22 pm »
Your code is correct, except for one thing. You destroy the StringList by calling Free, but in OnEditingDone you check whether the StringList is nil. How should the Stringlist become nil when you destroy it? Destroy only releases the occupied memory, but does not change the variable. So, in this case, it is better to call FreeAndNil(AStrLst) which also sets the variable to nil.

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: When select a new value in combobox raise exception
« Reply #12 on: October 05, 2020, 03:37:01 pm »
@WP

1) Well.. It's strange that function Assigned cannot check whether the address is valid or not. Isn't this possible? I wish there were one.

2)  Still, the OnEditingDone event should have been processed before calling OnDestroy. The StringList should be freed after the OnEditingDone have been processed, whatever method I use to close the form.

What I'm saying is that the order of eventhandlers matters.


 

TinyPortal © 2005-2018