Skip Menu |

This queue is for tickets about the Imager-Screenshot CPAN distribution.

Report information
The Basics
Id: 46933
Status: resolved
Priority: 0/
Queue: Imager-Screenshot

People
Owner: Nobody in particular
Requestors: robert [...] spitzenpfeil.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: screenshot(left=>....) keeps crashing
Date: Sun, 14 Jun 2009 12:26:03 +0200
To: bug-Imager-Screenshot [...] rt.cpan.org
From: Robert Spitzenpfeil <robert [...] spitzenpfeil.org>
Hi, I'm using screenshot to rapidly capture a small section of my screen and send it off to a display. When it fails, this is what die("error: $!") spits out: error: Resource temporarily unavailable at ./screen_video.pl line 66. I'm on opensuse 11.0 32bit I've attached my code. It would be nice if you could shed some light on why or what interferes here. Regards, Robert
#!/usr/bin/perl -W use strict; use Device::SerialPort; use Time::HiRes qw(sleep); use Imager; use Imager::Screenshot 'screenshot'; my $start_byte = "\n"; # 0x0A my $stop_byte = "\r"; # 0x0D my $color_scaler = 8; # image has 0-255 for each color, too much for the matrix board my $port = "/dev/ttyUSB0"; # <-- find right port ! my $link = Device::SerialPort->new($port) || die("could not open port: $port - $!"); # <-- match to right com port $link->databits(8); $link->baudrate(57600); # <-- match to arduino settings $link->parity("none"); $link->stopbits(1); $| = 1; # buffers disabled sleep 4; # wait until the arduino bootloader has timed out my $row; my $led; my $red; my $green; my $blue; my $alpha; my @scanline; my $img; my $newimg; my $line; my @coords; my $x; my $y; my $left; my $right; my $top; my $bottom; my $x_box_size = $ARGV[0] || 8; my $y_box_size = $ARGV[1] || 8; while (1) { @coords = `xinput query-state Mouse[1]`; # you need to adapt this to your system. use "xinput list" to get all X11 devices foreach $line ( @coords ) { $line =~ m/^.*valuator\[0\]\=(\d{1,4})/; $x = $1; $line =~ m/^.*valuator\[1\]\=(\d{1,4})/; $y = $1; } $left = $x-$x_box_size/2; $top = $y-$y_box_size/2; $right = $x+$x_box_size/2; $bottom = $y+$y_box_size/2; #print "x: ",$x,"\n"; #print "y: ",$y,"\n"; #print"xbs: ",$x_box_size,", ybs: ",$y_box_size,"\n"; #print $left,",",$top,",",$right,",",$bottom,"\n"; while ( ! defined($img) ) { $img = screenshot(left=>$left,right=>$right,top=>$top,bottom=>$bottom) || die("error: $!"); # on linux get the curser position using 'xinput query-state Mouse[1]' or similar sleep(0.020); } $newimg = $img->scale(xpixels=>8, ypixels=>8); undef($img); for ($row = 0; $row < 8; $row++) { $link->write($start_byte); @scanline = $newimg->getscanline(y=>$row); for ($led = 0; $led < 8; $led++) { ($red,$green,$blue,$alpha) = $scanline[$led]->rgba; $link->write(pack("C",$row)); $link->write(pack("C",$led)); $link->write(pack("C",$red/$color_scaler)); $link->write(pack("C",$green/$color_scaler)); $link->write(pack("C",$blue/$color_scaler)); #print $row,$led,"\n"; #print unpack("C",$image[$row*3*8+$led*3+0]),"\n"; #print unpack("C",$image[$row*3*8+$led*3+1]),"\n"; #print unpack("C",$image[$row*3*8+$led*3+2]),"\n\n"; sleep(0.001); } $link->write($stop_byte); sleep(0.001); } }
On Sun Jun 14 06:26:39 2009, robert@spitzenpfeil.org wrote: Show quoted text
> Hi, > > I'm using screenshot to rapidly capture a small section of my screen and > send it off to a display. > When it fails, this is what die("error: $!") spits out: > > error: Resource temporarily unavailable at ./screen_video.pl line 66. > > I'm on opensuse 11.0 32bit > > I've attached my code. It would be nice if you could shed some light on > why or what interferes here.
Sorry for not replying to this sooner, either rt.cpan.org didn't email the ticket to me, or I managed to delete it without realizing. To find the cause for failures of screenshot() your best choice is to display Imager->errstr, eg: $img = screenshot(left => ...) || die Imager->errstr I adapted your code, removing the serial port and xinput code, having it set $x and $y to random integers from 0 to 99. In each case it died when $x or $y was less than 4, setting $left or $top to a negative value. As documented, a negative left or top is treated as relative to the right or bottom edge of the window respectively. For the case of a small $x this will mean $left becomes large (near the right edge of the screen) while $right is small. screenshot can't return a zero or negative width image and fails with an error like: x: 79 y: 37 (75, 33, 83, 41) x: 2 y: 38 (-2, 34, 6, 42) image would be empty at ../../screen_video2.pl line 69. If you find you don't get the error above from Imager->errstr, please let me know and I'll track it down further. This does expose a documentation problem, as the behaviour on error isn't documented. Tony
Subject: Re: [rt.cpan.org #46933] screenshot(left=>....) keeps crashing
Date: Tue, 01 Dec 2009 03:21:33 +0100
To: bug-Imager-Screenshot [...] rt.cpan.org
From: Robert Spitzenpfeil <robert [...] spitzenpfeil.org>
Hi, I was busy, so I didn't investigate an further until now. Currently I can't really reproduce the error on my openSUSE 11.2 system. Before it was 11.0. I can reproduce the barf when the snapshot would go into negative values (mouse curser at TOP / LEFT). A lot of things around the X server have changed, so maybe that fixed it. If I run into it again, I'll let you know. My LED matrix is now happily displaying stuff under the mouse cursor. Thanks, Robert