Recent

Author Topic: Very Weird SIGSEGV  (Read 3624 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1179
Re: Very Weird SIGSEGV
« Reply #15 on: April 19, 2021, 06:05:38 pm »
Nice to hear you solved it.
Why do you have "Show;" in line 16 in function SetLabel?

dseligo

  • Hero Member
  • *****
  • Posts: 1179
Re: Very Weird SIGSEGV
« Reply #16 on: April 19, 2021, 06:09:17 pm »
So that is my first question - if a function returns an object as this does and I don't use the return value (don't do: var := setlabel()) is that a problem?  Setlabel is specific to this form and will place the label and "show" it

And I wanted to answer you to this one: if you don't need function result it's not a problem.

rwebb616

  • Full Member
  • ***
  • Posts: 133
Re: Very Weird SIGSEGV
« Reply #17 on: April 19, 2021, 06:09:34 pm »
Why do you have "Show;" in line 16 in function SetLabel?

Ah.. very interesting you ask that question.  This was another brain buster for me for a while.  I couldn't figure out why my labels were not positioning correctly and after doing all the debugging I found out that until you actually "Show" a label the width value is apparently some default value I think of 65 .. I couldn't understand why all my labels were width 65 no matter what the caption was and so I tried showing one and checked it then the size was correct and everything centered as expected.  So if I show it first then position it, it happens so quickly that the user never sees it.

Rich

speter

  • Sr. Member
  • ****
  • Posts: 338
Re: Very Weird SIGSEGV
« Reply #18 on: April 20, 2021, 02:15:41 am »
Two things:
1) Regarding 'show', make sure you set your labels to .visible := true [I think] this could replace the 'show';
2) There was a comment earlier about debug settings:
[...] Have you set all the debug checks (range, object ...  checking)? -CRriot -gt  (also try -gtt or -gttt)
Turned optimization to zero -O-
Added Heaptrc -gh  (additionally search the forum for "keepreleased" option of Heaptrc)

I think you have these settings ON, but just in case: select Project > Project Options > Compiler Options > Debugging > Checks and Assertion. Set all the options (I/O, Range, Overflow, Stack, Verify methods calls & include assertion code). Also make sure "Generatie info for the debugger..." is ticked. Finally (in the bottom section) do a run with "Use Heaptrc..." ON.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Very Weird SIGSEGV
« Reply #19 on: April 20, 2021, 04:25:03 am »
I don't see any problem with while loop... probably other error may have influenced there. 

rwebb616

  • Full Member
  • ***
  • Posts: 133
Re: Very Weird SIGSEGV
« Reply #20 on: April 20, 2021, 04:29:00 am »
I don't see any problem with while loop... probably other error may have influenced there.
I'm not sure but I think what was happening based on my line by line debug is that the while loop didn't run the code if the expression was true where the for loop ran regardless so for example if it ended up being:
Code: Pascal  [Select][+][-]
  1. for I:=0 to 0 do begin

based on count -1 being equal to zero then It would still run the code in the loop at least once. 

Rich

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Very Weird SIGSEGV
« Reply #21 on: April 20, 2021, 04:57:18 am »
I'm not sure but I think what was happening based on my line by line debug is that the while loop didn't run the code if the expression was true where the for loop ran regardless so for example if it ended up being:
Code: Pascal  [Select][+][-]
  1. for I:=0 to 0 do begin

based on count -1 being equal to zero then It would still run the code in the loop at least once. 

If "count - 1 = 0"  then "count = 1" therefore Item[0] does exist. So the loop can run once.

If "count = 0" then "count - 1 = -1"  and the loop would not run.


The only exception would be if count returned a "cardinal" because that can not go negative. But unless you have your own count function, that is not the case.

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Very Weird SIGSEGV
« Reply #22 on: April 20, 2021, 05:40:24 am »
This is not related with your problem, but for parsimony you can write followings:

   myLabel := TLabel.create(nil);
   myLabel.Name:=Name;
   myLabel.font.color := clWhite;
   myLabel.font.name := 'Roboto Black';
   created := labels.add(myLabel);
   Result := TLabel(labels[created]);

as:

   Result := TLabel.create(nil);
   labels.add(Result);
   Result.Name:=Name;
   Result.font.color := clWhite;
   Result.font.name := 'Roboto Black';

rwebb616

  • Full Member
  • ***
  • Posts: 133
Re: Very Weird SIGSEGV
« Reply #23 on: April 20, 2021, 07:33:52 am »
I'm not sure but I think what was happening based on my line by line debug is that the while loop didn't run the code if the expression was true where the for loop ran regardless so for example if it ended up being:
Code: Pascal  [Select][+][-]
  1. for I:=0 to 0 do begin

based on count -1 being equal to zero then It would still run the code in the loop at least once. 

If "count - 1 = 0"  then "count = 1" therefore Item[0] does exist. So the loop can run once.

If "count = 0" then "count - 1 = -1"  and the loop would not run.


The only exception would be if count returned a "cardinal" because that can not go negative. But unless you have your own count function, that is not the case.

I believe it was the latter .. it was -1 but with the for loop even though it was -1 it still went through the loop at least once.  I'm still learning where each style of loop is best suited.  It seems experience is the best teacher :)

Rich

rwebb616

  • Full Member
  • ***
  • Posts: 133
Re: Very Weird SIGSEGV
« Reply #24 on: April 20, 2021, 07:36:50 am »
This is not related with your problem, but for parsimony you can write followings:

   myLabel := TLabel.create(nil);
   myLabel.Name:=Name;
   myLabel.font.color := clWhite;
   myLabel.font.name := 'Roboto Black';
   created := labels.add(myLabel);
   Result := TLabel(labels[created]);

as:

   Result := TLabel.create(nil);
   labels.add(Result);
   Result.Name:=Name;
   Result.font.color := clWhite;
   Result.font.name := 'Roboto Black';


Ah yes, thank you for that.  I'm always looking for ways to make things read more simply. 

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Very Weird SIGSEGV
« Reply #25 on: April 20, 2021, 08:21:30 am »
Quote
with the for loop even though it was -1 it still went through the loop at least once.

No it doesn't, and it shouldn't.

rwebb616

  • Full Member
  • ***
  • Posts: 133
Re: Very Weird SIGSEGV
« Reply #26 on: May 03, 2021, 09:36:54 pm »
Quote
No it doesn't, and it shouldn't.

Yes, I agree with this - in theory it should not and running a quick test app I find that it does not (as it shouldn't) but for some reason during my debugging the for loop was running when the while loop did not.  Perhaps it has to do with the point at which the counter gets increased.

Rich

 

TinyPortal © 2005-2018