Recent

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

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #75 on: January 17, 2018, 06:41:57 pm »
Show the exact line that cause the error.
Ok, here you are:
Code: Pascal  [Select][+][-]
  1. end.
If i did not tell at least a dozen times, that the error happens at the very last line, then not even once...
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).
I'm no longer expecting that. I already gave it up.
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.
I already did this. We discussed this on the previous pages. If i comment out that single line which loads the images, then the error is gone. But until this point, no one could tell why this line
Code: Pascal  [Select][+][-]
  1. infoimg[Self.CEI].Picture.LoadFromStream(Self.Buffer);
- which works all along and causes no errors -  will crash the program when it reaches the end.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Segfault at the very end of the program
« Reply #76 on: January 17, 2018, 06:56:56 pm »
Maybe the problem is not in the code.

I have random crash issue when writing my glSlideshow. I found the culprit: some non standard tiff images.

Have you try to load different images? Or maybe run the code on other hardware/platform, I mean it could be hardware or virus or antivirus issue. Perhaps you can copy the source code (not the binary, to avoid infected by virus) to other computer, compile and run it?

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #77 on: January 17, 2018, 07:04:08 pm »
Maybe the problem is not in the code.

I have random crash issue when writing my glSlideshow. I found the culprit: some non standard tiff images.

Have you try to load different images?
The images are coming from youtube. You say, youtube may give faulty JPG-s and that cause the error? This is a new idea, i think it's worth a shot to validate the JPG-s and check if they are ok, or not.
Or maybe run the code on other hardware/platform, I mean it could be hardware or virus or antivirus issue. Perhaps you can copy the source code (not the binary, to avoid infected by virus) to other computer, compile and run it?
My hardware is fine, no other issues. And i think it has a pretty low chance that my Linux is infected with some virus.

Update: Nope, all of the pictures were valid.
« Last Edit: January 17, 2018, 07:13:46 pm by TCH »

balazsszekely

  • Guest
Re: Segfault at the very end of the program
« Reply #78 on: January 17, 2018, 07:14:14 pm »
I already did this. We discussed this on the previous pages. If i comment out that single line which loads the images, then the error is gone. But until this point, no one could tell why this line
Code: Pascal  [Select][+][-]
  1. infoimg[Self.CEI].Picture.LoadFromStream(Self.Buffer);
- which works all along and causes no errors -  will crash the program when it reaches the end.
Excelent! Then all you have to do is:
infoimg[Self.CEI].Picture.Graphics.Assign(YourImage)
Create "YourImage" first, load it from stream, after assign don't forget to free it(the stream too). I saw something similar error in the past.

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #79 on: January 17, 2018, 07:36:43 pm »
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. var img: TImage;
  3. begin
  4.      img := TImage.Create(Form1); // does not works with nil either
  5.      img.Picture.LoadFromStream(Self.Buffer);
  6.      infoimg[Self.CEI].Picture.Graphic.Assign(img);  //LoadFromStream(Self.Buffer);
  7.      img.free;
  8. end;
SIGSEGV, right at that line.

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Segfault at the very end of the program
« Reply #80 on: January 17, 2018, 08:45:56 pm »
Is this thread issue?

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Segfault at the very end of the program
« Reply #81 on: January 17, 2018, 09:00:57 pm »
Is this thread issue?
Like:
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. var img: TImage; // this is a stack local variable...
  3. begin
  4.      img := TImage.Create(Form1); // does not works with nil either
  5.      try
  6.        img.Picture.LoadFromStream(Self.Buffer);
  7.        infoimg[Self.CEI].Picture.Graphic.Assign(img);  //LoadFromStream(Self.Buffer);
  8.     finally
  9.       img.free;  // this is better but how are you gonna show it? There IS no picture here.... THINK
  10.     end;
  11. end;
If you need the picture outside of the procedure, declare it outside of the procedure....make it a member of the image  thread. (at the very least: I can predict you have more questions later, I am a witch)
« Last Edit: January 17, 2018, 09:10:11 pm by Thaddy »
Specialize a type, not a var.

balazsszekely

  • Guest
Re: Segfault at the very end of the program
« Reply #82 on: January 17, 2018, 09:06:56 pm »
@TCH
That's not what I meant, for example if you work with png's:
Code: Pascal  [Select][+][-]
  1. uses graphics;
  2.  
  3. var
  4.   Png: TPortableNetworkGraphic;
  5.   Buffer: TMemoryStream;
  6. begin
  7.   Buffer := TMemoryStream.Create;
  8.   try
  9.     //you already have a stream, set positon to 0
  10.     Buffer.Loadfromfile('D:\downloads\tch.png');
  11.     Buffer.position := 0;
  12.     //end comment
  13.     Png := TPortableNetworkGraphic.Create;
  14.     try
  15.       Png.LoadFromStream(Buffer);
  16.       Image1.Picture.Graphic := Png
  17.      //infoimg[Self.CEI].Picture.Graphic := Png;
  18.     finally
  19.       Png.Free;
  20.     end;
  21.   finally
  22.     Buffer.Free
  23.   end;
  24. end;

What is Buffer TMemoryStream, TResourceStream?
« Last Edit: January 17, 2018, 09:11:00 pm by GetMem »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Segfault at the very end of the program
« Reply #83 on: January 17, 2018, 09:11:51 pm »
That's a lot better. I added to my comment btw. explanation why the picture can not be local.
Specialize a type, not a var.

balazsszekely

  • Guest
Re: Segfault at the very end of the program
« Reply #84 on: January 17, 2018, 09:15:52 pm »
Quote
@Thaddy
I added to my comment btw. explanation why the picture can not be local.
That's not true, after he assign the png to infoimg[Self.CEI].Picture.Graphic the png can be freed(see my example) because Infoimg[Self.CEI] it's not a local variable.

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #85 on: January 17, 2018, 09:37:39 pm »
@bytebites: Not it isn't.

@Thaddy, @GetMem: I declared the TJpegImage in the thread and created/destructed it in the thread constructor/destructor. And then:
Code: Pascal  [Select][+][-]
  1. procedure TImageThread.LoadAPicture;
  2. begin
  3.      Self.Buffer.Position := 0;
  4.      Self.img.LoadFromStream(Self.Buffer);
  5.      infoimg[Self.CEI].Picture.Graphic := Self.img;
  6. end;
No change, still crashes at the end. If i move the TJpegImage creation/destruction into the function, nothing changes, crash at the end. Buffer is TMemoryStream.

balazsszekely

  • Guest
Re: Segfault at the very end of the program
« Reply #86 on: January 17, 2018, 09:42:46 pm »
OMG! Are you creating the JPG inside a thread and assign it to TImage located in the main GUI without synchronize? That's a capital sin.  :D No wonder your application crash.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Segfault at the very end of the program
« Reply #87 on: January 17, 2018, 09:48:46 pm »
OMG! Are you creating the JPG inside a thread and assign it to TImage located in the main GUI without synchronize? That's a capital sin.  :D No wonder your application crash.
You beat me  ;D
I was just about to write something similar.

TCH, if that is the case then you must use synchronize, critical sections or use something like this:
http://forum.lazarus.freepascal.org/index.php/topic,38851.msg265181.html#msg265181
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

TCH

  • Full Member
  • ***
  • Posts: 200
Re: Segfault at the very end of the program
« Reply #88 on: January 17, 2018, 09:57:52 pm »
No. The functon "TImageThread.LoadAPicture;" is called by Synchronize. In procedure TImageThread.Execute;:
Code: Pascal  [Select][+][-]
  1.                         if (Self.Buffer.Size > 0) then
  2.                         begin
  3.                              Self.CEI := idx;
  4.                              Self.Buffer.Position := 0;
  5.                              Synchronize(@LoadAPicture);
  6.                         end;
Glad you're ready to chastise me without asking if your hypothesis is correct...
« Last Edit: January 17, 2018, 09:59:48 pm by TCH »

balazsszekely

  • Guest
Re: Segfault at the very end of the program
« Reply #89 on: January 17, 2018, 10:10:50 pm »
Quote
Glad you're ready to chastise me without asking if your hypothesis is correct...
That wasn't obvious from your previous code. Since you don't show more code we have to create hypothesis.
Is this true:
1. If you remove all threads the error is still there
2. The error is gone if you remove line infoimg[Self.CEI].Picture.Graphic := Png, which is an array of TImages?


 

TinyPortal © 2005-2018