Recent

Author Topic: Segfault at the very end of the program  (Read 30706 times)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Segfault at the very end of the program
« Reply #60 on: November 07, 2017, 11:56:46 pm »
Instead of just .Free, try FreeAndNil(objectName).

Basically referring to case where you would do this multiple times
Code: Pascal  [Select][+][-]
  1.      for i := 0 to 19 do
  2.      begin
  3.           infotx[i].Free;
  4.           infoimg[i].Free;
  5.      end;
infotx is not automatically nil after .Free unless you set it to.
« Last Edit: November 07, 2017, 11:58:19 pm by User137 »

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #61 on: November 08, 2017, 08:46:05 am »
Nope, no change.

It's still crashing at the exit. Now after the label of SYSTEM_$$_REMOVE_FREED_FIXED_CHUNKS$POSCHUNK

And if it's crashing when clearing the image then the crash occurs after the label of

CLASSES$_$TPERSISTENT_$__$$_FPONOTIFYOBSERVERS$TOBJECT$TFPOBSERVEDOPERATION$POINTER

Do these names tell anything to anyone?

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Segfault at the very end of the program
« Reply #62 on: December 15, 2017, 02:56:11 pm »
I have the same problem. I use a VirtualTreeView, and after I edit a value, the component isn't destroyed. It shows status "Destroying", it closes the thread, if used, but it isn't actually removed. Calling "Free" makes no difference.

Except... It only happens in debug mode. And why would I care? Windows will remove all the memory used on program exit anyway.

So, it crashes when debugging. And I spend hours trying to fix it, without success. I just have to remember to run it without debugging before distributing it.

Thaddy

  • Hero Member
  • *****
  • Posts: 14166
  • Probably until I exterminate Putin.
Re: Segfault at the very end of the program
« Reply #63 on: December 15, 2017, 05:18:43 pm »
Such code can have major side effects, always do a top down so not
Code: Pascal  [Select][+][-]
  1.  for i := 0 to 19 do
  2.      begin
  3.           infotx[i].Free;
  4.           infoimg[i].Free;
  5.      end;

BUT:
Code: Pascal  [Select][+][-]
  1.  for i := 19 downto 0 do
  2.      begin
  3.           infotx[i].Free;
  4.           infoimg[i].Free;
  5.      end;

Always. Even if it does not work in your case, always apply defensive programming practise. Even if you think you know better.

Ignore silly responses. Do what I say. Some programmers here use FreeAndNil way to often: it indicates they are not sure about their code and it is usually not necessary at all. IOW shows bad skills.
« Last Edit: December 15, 2017, 05:38:24 pm by Thaddy »
Specialize a type, not a var.

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #64 on: January 07, 2018, 07:07:25 pm »
I tried to free them objects in the reverse way. Nothing changed, segfault at exit.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Segfault at the very end of the program
« Reply #65 on: January 07, 2018, 08:58:31 pm »
If you can't share the complete compilable code (or at least a cut-down version of your project with typical but anonymised data that demonstrates the bug so others can reproduce the error) then there is little chance that prolonging this forum thread will be of help to you.

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #66 on: January 14, 2018, 01:42:09 pm »
The crash occurs at the very end of the program at the line "end.".
I have no idea what part causes this.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Segfault at the very end of the program
« Reply #67 on: January 14, 2018, 01:57:52 pm »
The crash occurs at the very end of the program at the line "end."
I have no idea what part causes this.

Nor will anyone else have a (definitive) idea without access to compilable code that produces this crash.
Perhaps you are content just to gather from forum users ever more guesses about possible causes  indefinitely?

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #68 on: January 14, 2018, 02:04:13 pm »
No. I think, i'll rewrite it from scratch... The error is undebuggable, so the code is beyond repair.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Segfault at the very end of the program
« Reply #69 on: January 14, 2018, 09:15:48 pm »
I've had such problems and it was in the clean up of the background functions, in my case it was the
memory manager trying to clean itself up but a couple memory links got corrupted and pointed to
space that didn't belong to it.

  it was my code that was doing it, I had a memory overwrite that clobbered a pointer.

 I don't know if that is your issue but I get it can be resolved.
The only true wisdom is knowing you know nothing

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #70 on: January 17, 2018, 10:52:52 am »
How?

Threads have been ruled out, i have "monothreadized" the program and the crash still occurs.

The custom tabbar have been ruled out, for the original concept used the built-in tabbar component of Lazarus and the crash have occurred then too.

Dynamically created TImage-s and TMemo-s have been ruled out, i have been removed and replaced all of them with manually placed components on the main form and wrote a wrapper function which gaves back their pointer by an index number and the crash is still persistent.

And the crash happens at the very end of the program, so i cannot just step-by-step debug it.

I must have committed something during the development which made the code fundamentally broken, thus beyond repair. For now, the full rewrite seems the only working option for me.

But if you have a suggestion about what kind of overwrite i should search for, then i'm still open for anything. But i still cannot publish the source.
« Last Edit: January 17, 2018, 10:59:56 am by TCH »

Thaddy

  • Hero Member
  • *****
  • Posts: 14166
  • Probably until I exterminate Putin.
Re: Segfault at the very end of the program
« Reply #71 on: January 17, 2018, 11:40:17 am »
<Sigh> show us your latest code... Preferably condensed to a bare minimum.
We will solve it in minutes, not hours. You are really stubborn: you made a mistake, we can only point it out if you show real code...
Specialize a type, not a var.

Lutz Mändle

  • Jr. Member
  • **
  • Posts: 65
Re: Segfault at the very end of the program
« Reply #72 on: January 17, 2018, 12:18:01 pm »
Which widgetset (gtk2, qt4, qt5) you are using? Have you tried to change it?

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #73 on: January 17, 2018, 01:47:26 pm »
<Sigh> show us your latest code... Preferably condensed to a bare minimum.
We will solve it in minutes, not hours. You are really stubborn: you made a mistake, we can only point it out if you show real code...
I cannot show the entire code. I could show parts, but which part i should show? I have no idea where is the problem.
Which widgetset (gtk2, qt4, qt5) you are using? Have you tried to change it?
Under Linux/FreeBSD, it's GTK2. Under OSX (PowerPC and x86) i use the OS' widgetset (Cocoa, i think.). The crash occurs everywhere. It's not the widgetset.

balazsszekely

  • Guest
Re: Segfault at the very end of the program
« Reply #74 on: January 17, 2018, 05:15:00 pm »
Quote
@TCH
I cannot show the entire code. I could show parts, but which part i should show?
Show the exact line that cause the error. Now seriously what are you doing is make no sense. You don't want to show the code(which is OK), but you still expect us to somehow guess where the error is(this is annoying).
Just comment out 60% of your application, do a quick test. If there is no error add back 10% and so on. With this method you should find in less then an hour where the bug is, especially since you're familiar with your own code.
« Last Edit: January 17, 2018, 05:20:58 pm by GetMem »

 

TinyPortal © 2005-2018