无法在GooCanvas中画线

时间:2019-02-15 08:59:14

标签: perl canvas gtk

在Perl / Gtk3脚本中并使用GooCanvas,我可以轻松地绘制矩形,省略号或其他内容,但是似乎无法绘制简单的线条。

通过调用Goo :: CanvasPolyline-> new()绘制线。该行的坐标由对Goo :: CanvasPoints-> new()的调用指定,但是该调用会产生以下错误:

require

我已经尝试了Perl模块Goo :: Canvas和更现代的GooCanvas2;两者都会产生相同的错误。

我找不到任何有效的代码示例;只是下面的无效脚本,Google在$ RANDOM_WEBSITE上找到了。

GLib-ERROR **: ../../../../glib/gmem.c:105: failed to allocate 18446744069314558208 bytes at /usr/lib/x86_64-linux-gnu/perl5/5.26/Glib/Object/Introspection.pm line 67.
Aborted (core dumped)

1 个答案:

答案 0 :(得分:1)

  

my $points = Goo::CanvasPoints->new( $pts_ref );

根据the documentation,构造函数应采用要保留的点数,而不是对points数组的引用。因此,您可以尝试:

[...]
# first point set
my $pts_ref = [50,50,180,120,90,100,50,50];
my $num_points = (scalar @$pts_ref)/2;
my $points = Goo::CanvasPoints->new( $num_points );

# Set the points:
my $j = 0;
for my $i (0..($num_points -1)) {
    my $x = $pts_ref->[$j];
    my $y = $pts_ref->[$j+1];
    $points->set_point($i, $x, $y);
    $j += 2;
}
[...]