artem78 / AutoScreenshot

Automatic screenshot maker
GNU General Public License v3.0
133 stars 22 forks source link

Screenshots fail with "Cannot get raw image from device" #35

Closed billybednar closed 1 year ago

billybednar commented 1 year ago

Describe the bug After upgrading to v1.11, taking a screenshot fails 100% of the time with the error "Cannot get raw image from device." This occurs for both manual and automatic captures. If OK is clicked, the program continues but no screenshot is saved. If abort is clicked, the program exits. If nothing is clicked and automatic screenshot are on, the program exits when the next attempt fails occurs.

To Reproduce

  1. Click "Take screenshot"

Screenshots image

Version v1.11

OS Windows 10 Pro 22H2 (build 19045.2965), 64 bit

Additional context Works again after reverting to 1.10.4, although in the past I've occasionally had corrupt screenshots like the one in #32.

Log file log.txt - doesn't look like anything useful

jessedufrene commented 1 year ago

Same issue with me on 1.11 portable version, running Windows 11 22H2.

It also worked fine before on 1.10.4 and 1.10.3 portable versions

I even tried deleting my config and using default settings, still the same issue.

artem78 commented 1 year ago

@billybednar How many displays do you have/capture from? And which resolution?

artem78 commented 1 year ago

Show your config.ini.

Try this build. Is the problem still exists?

AutoScreenshot_v1.11-3-g7872c3e-dirty_Windows_portable.zip

artem78 commented 1 year ago

Same issue with me

@jessedufrene Could you also attach your log?

jessedufrene commented 1 year ago

log.txt - i manually triggered screenshots twice. i hit ok the first time, and abort the second time.

i've got 3 displays, a total of 5760x1200

just tried the 1.11-3 build and it looks like it works fine

billybednar commented 1 year ago

3 displays arranged with an offset. It fails when capturing from all monitors or either of the secondary monitors, but not the primary (the one in blue).

It also occurs with the default generated config.ini.

The new build fixes it.

artem78 commented 1 year ago

Thanks for important information.

Just another check: AutoScreenshot_v1.11-2-g6edfe70_Windows_portable.zip

Is the bug occurs in this build or not?

billybednar commented 1 year ago

The bug is back in that build. I tried rearranging the monitors many different ways and the positions definitely have an impact on it. Unfortunately I couldn't figure out exactly what the pattern is.

While testing these, I noticed that you get an access violation when opening a portable copy if there is already an instance running out of a different location. It only happens the first time when there is no config.ini. If you try again, it will exit cleanly instead of crashing. I can make a separate bug with more details if you want.

artem78 commented 1 year ago

Unfortunately I couldn't figure out exactly what the pattern is.

I found it. The error occurs if you have any display above or to the left of the primary one. Like in this example:

2023-06-08_215000

In this case top-left coordinate of all visible area will be negative and this cause fails after some modifications in v1.11.

For comparision in this case capturing works fine:

2023-06-08_215329

artem78 commented 1 year ago

In logs you send me there is negative coordinates:

[07:57:40.303] Region: l=-1680,t=-1080,r=1920,b=1080

and

[10:07:43.278] Region: l=-1920,t=0,r=3840,b=1200

artem78 commented 1 year ago

I can make a separate bug with more details if you want.

Yes, please make separate issue report for another problem.

billybednar commented 1 year ago

Looks like the Windows implementation of RawImage_FromDevice takes a screenshot of the entire desktop with the incorrect assumption that the upper-left corner is (0, 0) and then tries to extract the desired region from the bitmap.

artem78 commented 1 year ago

@billybednar I thought this is TBGRABitmap.LoadFromDevice bug from external package. I don't observe this problem in Linux. In Windows BitBlt function may be used directly. I used this solution:

var
  Bitmap: TBGRABitmap;  

......

{$IfDef Windows}
  BitBlt(Bitmap.Canvas.Handle, 0, 0, ARect.Width, ARect.Height,
           ScreenDC, ARect.Left, ARect.Top, SRCCOPY);
{$EndIf}
{$IfDef Linux}
  Bitmap.LoadFromDevice(ScreenDC, ARect);
{$EndIf}
artem78 commented 1 year ago

I think you should create issue report in Lazarus repository.

artem78 commented 1 year ago

Fixed in v1.12. Please check.

circular17 commented 7 months ago

Hello. I'm popping by to notify that I've created the bug report 40857 for Lazarus. I suggest you have a look.

Regards