Recent

Author Topic: Ubuntu problem with Jpg LoadFromDevice into multithreading  (Read 2456 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Ubuntu problem with Jpg LoadFromDevice into multithreading
« on: October 18, 2020, 12:21:40 am »
Hello everybody. I have a problem. I have a program that uses multithreading and within secondary threads it uses this procedure. On windows and mac os it doesn't work properly. On ubuntu instead it makes me crash the program. The line is that of the LoadFromDevice. Can anyone tell me why?
The procedure works correctly in the main thread (form1).

Code: Pascal  [Select][+][-]
  1. procedure GetDesktopImage(MyImg: TJpegImage);
  2. var
  3.   ScreenDC   : HDC;
  4. begin
  5.      if Assigned(MyImg) then
  6.      begin
  7.        ScreenDC   := GetDC(0);
  8.        try
  9.           try
  10.              MyImg.PixelFormat := pf32bit;
  11.              MyImg.LoadFromDevice(ScreenDC);
  12.              MyImg.CompressionQuality:=Self.FQuality; //100 = best quality, 25 = pretty awful
  13.           finally
  14.             ReleaseDC(0,ScreenDC);
  15.          end;
  16.        except
  17.              on E: Exception do
  18.              begin
  19.                      writeln(E.Message);
  20.              end;
  21.        end;
  22.      end;
  23. end;
  24.  
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #1 on: October 18, 2020, 01:06:22 pm »
Example who reproduce error.
Terminal write:

Failed to load module "canberra-gtk-module"
[DEBUG] Name com.canonical.AppMenu.Registrar does not exist on the session bus

Pre error
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
test: ../../src/xcb_io.c:163: dequeue_pending_request: asserzione "!xcb_xlib_unknown_req_in_deq" non riuscita.
Annullato (core dump creato)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #2 on: October 19, 2020, 07:14:25 am »
No idea?!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #3 on: October 19, 2020, 08:57:16 am »
Hello,

For information, your project doesn't compile at all, on my computer (Ubuntu): "the project (test.lpr) has no main source file.".
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #4 on: October 19, 2020, 09:17:31 am »
Probably because I use the trunk version of lazarus and fpc. Just from the project analyzer add the * .lpr file from the file system and LCL as a dependency.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #5 on: October 19, 2020, 09:23:37 am »
Done: don't compile either.
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #6 on: October 19, 2020, 09:36:04 am »

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #7 on: October 19, 2020, 10:10:45 am »
No, fixlp doesn't correct the "test" project, on my computer in any case (no time to investigate why now):

Code: Bash  [Select][+][-]
  1. sudo test.lpi
  2. Processing test.lpi...
  3. An unhandled exception occurred at $00000000004CEEBB:
  4. EFOpenError: Unable to open file "test.lpi"
  5.   $00000000004CEEBB line 151 of lazutf8classes.pas
  6.   $00000000004CECB8 line 129 of lazutf8classes.pas
  7.   $0000000000486991 line 4186 of laz2_xmlread.pas
  8.   $0000000000401D9A line 132 of fixlp.lpr
  9.   $0000000000401FC7 line 160 of fixlp.lpr

By the way: my SVN-RabbitVCS reports, that currently fpc is no longer in the svn HEAD (already reported here: https://forum.lazarus.freepascal.org/index.php/topic,51828.msg381191.html#msg381191).
« Last Edit: October 19, 2020, 10:15:38 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #8 on: October 19, 2020, 10:16:59 am »
Done: don't compile either.

Add umain.pas from project analyzer
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #9 on: October 19, 2020, 10:21:45 am »
Maybe you should do the screen capture in the main thread.
https://wiki.freepascal.org/Multithreaded_Application_Tutorial

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #10 on: October 19, 2020, 10:29:34 am »
Quote
Add umain.pas from project analyzer

Done (add test.lpr and umain.pas as files, LCL as package, with the Project inspector): same message.


Okay, I recreated the project. I've got: class 'FPImageException' with message: Failed toget raw image from device on line MyImg.LoadFromDevice(ScreenDC);, too.
« Last Edit: October 19, 2020, 11:00:06 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #11 on: October 19, 2020, 10:55:22 am »
Maybe you should do the screen capture in the main thread.
https://wiki.freepascal.org/Multithreaded_Application_Tutorial

I can't for performance reasons. If I have to switch to the main thread every time it slows down too much. I'd rather avoid. Because actually in the application I want to create I not only have an additional thread, but at least 4 others.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #12 on: October 19, 2020, 10:56:00 am »
Has anyone been able to compile and run it in order to reproduce the error?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #13 on: October 19, 2020, 11:00:48 am »
I have the same error, and...:
Quote
WARNING: TGtk2WidgetSet.RawImage_FromDrawable: gdk_image_get failed
Failed to get raw image from device.
... from gtk2widgetset.inc, line Image := gdk_image_get(ADrawable, ARect.Left, ARect.Top, ADesc.Width, ADesc.Height); , which raises the exception class 'FPImageException' with message: Failed toget raw image from device on line MyImg.LoadFromDevice(ScreenDC);.

==> So, it's not due to a specific problem with the GTK layer of your computer.
« Last Edit: October 19, 2020, 11:56:00 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Ubuntu problem with Jpg LoadFromDevice into multithreading
« Reply #14 on: October 19, 2020, 11:20:08 am »
Maybe you should do the screen capture in the main thread.
https://wiki.freepascal.org/Multithreaded_Application_Tutorial

I can't for performance reasons. If I have to switch to the main thread every time it slows down too much. I'd rather avoid. Because actually in the application I want to create I not only have an additional thread, but at least 4 others.

Hi!

So this is error by design.
Read the link from bytebites again.

Winni

 

TinyPortal © 2005-2018