Recent

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

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #30 on: November 02, 2017, 03:54:49 pm »
@Munair: Even with Synchronize?

@taaz:
I've tried both of your approaches
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. var tmpimg: TImage;
  3. begin
  4.      EnterCriticalSection(Section);
  5.      tmpimg := infoimg[Self.CEI];
  6.      infoimg[Self.CEI] := nil;
  7.      LeaveCriticalSection(Section);
  8.      tmpimg.Picture.LoadFromStream(Self.Buffer);
  9.      EnterCriticalSection(Section);
  10.      infoimg[Self.CEI] := tmpimg;
  11.      LeaveCriticalSection(Section);
  12. end;
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. begin
  3.      EnterCriticalSection(Section);
  4.      try
  5.         infoimg[Self.CEI].Picture.LoadFromStream(Self.Buffer);
  6.      finally
  7.         LeaveCriticalSection(Section);
  8.      end;
  9. end;
and no avail. Still crashes at exit.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Segfault at the very end of the program
« Reply #31 on: November 02, 2017, 04:03:05 pm »
I would first test your class thoroughly without threads and then proceed to the next step.

Still, whenever you can modify interface related elements without thread, that would be my first choice (and priority).
keep it simple

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #32 on: November 02, 2017, 04:18:07 pm »
If i disable the image thread, then it works. Now i tried a different approach. I did not loaded the Image array from the thread, but i did load a TMemoryStream array and then when needed to draw, i loaded the contents into the images. Still crashes.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Segfault at the very end of the program
« Reply #33 on: November 02, 2017, 04:19:41 pm »
@Munair: Even with Synchronize?

@taaz:
I've tried both of your approaches
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. var tmpimg: TImage;
  3. begin
  4.      EnterCriticalSection(Section);
  5.      tmpimg := infoimg[Self.CEI];
  6.      infoimg[Self.CEI] := nil;
  7.      LeaveCriticalSection(Section);
  8.      tmpimg.Picture.LoadFromStream(Self.Buffer);
  9.      EnterCriticalSection(Section);
  10.      infoimg[Self.CEI] := tmpimg;
  11.      LeaveCriticalSection(Section);
  12. end;
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. begin
  3.      EnterCriticalSection(Section);
  4.      try
  5.         infoimg[Self.CEI].Picture.LoadFromStream(Self.Buffer);
  6.      finally
  7.         LeaveCriticalSection(Section);
  8.      end;
  9. end;
and no avail. Still crashes at exit.
well given that those where not approaches only examples of proper use under conditions I would have to say that the only logical step now is for you to post the code.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Segfault at the very end of the program
« Reply #34 on: November 02, 2017, 04:20:24 pm »
If i disable the image thread, then it works. Now i tried a different approach. I did not loaded the Image array from the thread, but i did load a TMemoryStream array and then when needed to draw, i loaded the contents into the images. Still crashes.

You disabled the thread but do you still load the images without the thread?
keep it simple

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #35 on: November 02, 2017, 04:39:31 pm »
well given that those where not approaches only examples of proper use under conditions I would have to say that the only logical step now is for you to post the code.
I cannot do that. I would like to use this program for semi-commercial purposes and if i publish the code, then i can wave bye-bye to that.
You disabled the thread but do you still load the images without the thread?
DOH! No, i did not. I've only disabled the thread. And you're right, even if the imagethread is disabled, if i load the images, then the program segfaults when terminating. I'm gonna rid of the threads now and see.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Segfault at the very end of the program
« Reply #36 on: November 02, 2017, 04:50:05 pm »
You disabled the thread but do you still load the images without the thread?
DOH! No, i did not. I've only disabled the thread. And you're right, even if the imagethread is disabled, if i load the images, then the program segfaults when terminating. I'm gonna rid of the threads now and see.

Like I said, you must explore ALL options without threads. Then you probably could resolve this without a lengthy topic.  ;)
keep it simple

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #37 on: November 02, 2017, 07:22:12 pm »
I've removed all the threads, now the program is completely monothreaded. GDB results when exiting:
Code: [Select]
(gdb) run
Starting program: /media/ROOTDIR/lw/ytfe/ytfe
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
ERROR in LCL: TResourceCacheItem.DecreaseRefCount=0 TResourceCacheItem
Creating gdb catchable error:

  $000000000052AAD9 line 720 of lazloggerbase.pas
  $00000000004E1457 line 1456 of lclproc.pas
  $00000000004DF62F line 901 of lclproc.pas
  $00000000005994BC line 200 of lclrescache.pas
  $00000000005993EF line 206 of lclrescache.pas
  $000000000055BF48 line 196 of include/brush.inc
  $000000000055BC95 line 108 of include/brush.inc
  $0000000000430640
  $000000000062B0A3 line 6569 of include/wincontrol.inc

Program received signal SIGFPE, Arithmetic exception.
0x00000000004df669 in RAISEGDBEXCEPTION (
    MSG=0x7ffff7fcb898 'TResourceCacheItem.DecreaseRefCount=0 TResourceCacheItem') at lclproc.pas:902
902       if (length(Msg) div (length(Msg) div 10000))=0 then ;
What is this
Code: [Select]
ERROR in LCL: TResourceCacheItem.DecreaseRefCount=0 TResourceCacheItemerror? No relevant hit in google.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Segfault at the very end of the program
« Reply #38 on: November 03, 2017, 08:32:39 am »
@howardpc:
This is the creation's part:
Code: Pascal  [Select][+][-]
  1.      tabs := TButtonTabList.Create(Form1);
  2.      tabs.IgnoreTabTextChanges := true;
  3.      tabs.Left := 0;
  4.      tabs.Top := 24;
  5.      tabs.OnChange := @tabsChange;
  6.      tabs.OnCloseBtnClick := @tabsClose;
The rest would be too much to elaborate. I use it exactly like the normal TTabControl (actually i imitated it), but i needed a close button on all tabs. Here is the current beta of my program (not stripped, debug info is still inside), in which you can see what i would like to do with it: http://oscomp.hu/depot/ytfe.dbg
I tried to correct the memory leaks and incorrect creation/destruction of subcomponents in your TButtonTabList, but found design flaws made it simpler to rewrite from scratch based on your ideas, which are good.
I've implemented an alternative which is attached, together with a small exerciser program to test the implementation. AFAIK it has no memory leaks or unexpected errors through attempts to free subcomponents twice. Although I'm not sure precisely what you need, you may be able to adapt the attached code to do exactly what you want.
The problems with your TButtonTablist code may not be the sole cause of errors in your larger program, but they must be a contributory factor, and will probably not surface until program closedown when finalization and destruction of scores of owned subcomponents takes place.
« Last Edit: November 03, 2017, 08:36:16 am by howardpc »

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #39 on: November 03, 2017, 01:09:18 pm »
Thank you for your efforts. Unfortunately i couldn't compile your example, as it told me
Code: [Select]
uclosetablist.pp(707,6) Error: Identifier not found "MouseInClient"I've checked this and it seems it's part of TWinControl. Which object this call wants to refer? Self.MouseInClient did not work.

Also, could you please elaborate where did you found memory leaks and incorrect creation and destruction in my unit? I would like to know what did i erroneously.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Segfault at the very end of the program
« Reply #40 on: November 03, 2017, 01:42:52 pm »
Ah, this is a recent change in trunk.
MouseEntered is deprecated in favour of MouseInClient.
Just change MouseInClient to MouseEntered and all should be well.

To detail the flaws in TButtonTabList would require longer than I have at the moment, since I'll be away from computers for the weekend, and the answer to your question is not a one-liner.
I'll send you a PM with my thoughts on that next week.

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #41 on: November 03, 2017, 02:00:20 pm »
Yes, it compiles now, thanks.
Your tablist is very nice, supports a wider range of features. Although i need that if a button is pushed, then the last pushed button is pulled, because i need one active tab. But i could implement that, but unfortunately i cannot use your unit, because it's GPL and if i incorporate a GPL unit into my sources, then i have to release my sources.

Okay, i'll await your answer, thank you.

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: Segfault at the very end of the program
« Reply #42 on: November 03, 2017, 02:09:51 pm »
Yes, it compiles now, thanks.
Your tablist is very nice, supports a wider range of features. Although i need that if a button is pushed, then the last pushed button is pulled, because i need one active tab. But i could implement that, but unfortunately i cannot use your unit, because it's GPL and if i incorporate a GPL unit into my sources, then i have to release my sources.

Okay, i'll await your answer, thank you.
It is a GPL with linker exception, so you can use it w/o publishing your code. You are only not allowed to modify the component itself: any modified version of the component must be published under the same GPL or a compatible license.
Specialize a type, not a var.

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #43 on: November 03, 2017, 04:57:33 pm »
I see, but still, since i would need to modify it (because of the multi push), the result is the same.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Segfault at the very end of the program
« Reply #44 on: November 07, 2017, 12:19:48 pm »
The licence only requires you to publish the source of the unit if you modify it. You are not required to publish any closed source code for other units or for your program.
The idea is that no one writes 100% bug-free code.
Other users and other eyes may encounter bugs and correct them, or extend the original source in an innovative way that is a genuine improvement. The licence simply says that any such bug fixes or improvements should be shared, so that the overall quality of open source offerings increases.

The problem with the code you shared is that your Synchronize method creates multiple Toggleboxes and Buttons, all owned by Owner. In spite of Owner being specified as the manager of the destruction of these controls, Synchronize later adjusts the number of Toggleboxes and Buttons, and proceeds to Free unwanted boxes and buttons. I think this causes problems at the program end when Owner attempts to destroy instances that your code earlier freed.

Following this thread has given me a better idea of the kind of tab container you are after (similar to a TRadioGroup in functionality). Accordingly I have written a tab control that is closer to what you want. A program is attached which exercises this control.

 

TinyPortal © 2005-2018