Is there a maximum number of points permitted in a single line in Tk::Canvas? If there is, is there some way to change it?

When I try to plot a line with more than 1048572 points, my script exits. The exit occurs after the callback containing the createLine call returns. Sometimes, I get the message

X connection to :2.0 broken (explicit kill or server shutdown).

on exit, sometimes not. It isn't a maximum number of points in the canvas; I can plot many lines of 1048572 points, but no lines of 1048573 points. Note that 1048572 is very close to 1024*1024 (2^10 or 1048576), but I couldn't find either number anywhere in the Perl::Tk source. Here is an example script to show the problem. I am running under Solaris 5.10 on a SPARC Enterprise M5000, displaying on a SunRay 2FS. Perl version is 5.8.8, Perl::Tk is 804.028, all compiled under the Sun Studio 11 compiler, 64 bit.

use Tk; use strict; use warnings; my ($wf_canvas, $wid); my $mw = MainWindow->new; $mw->geometry("600x300+10+10"); my $menubar_frame = $mw->Frame(-relief => 'ridge', -borderwidth => 2) ->pack(-side => 'top', -anchor => 'n', -fill => 'x'); my $plot1_button = $menubar_frame->Button( -command => [\&plotwave1], -text => 'Plot short') ->pack(-side => 'left'); my $plot2_button = $menubar_frame->Button( -command => [\&plotwave2], -text => 'Plot long') ->pack(-side => 'left'); my $exit_button = $menubar_frame->Button( -command => sub {$mw->destroy}, -text => 'Exit') ->pack(-side => 'left'); MainLoop; exit; sub wfplot_canvas() { if (! Exists($wf_canvas)) { $wf_canvas = $mw->Canvas(-background => 'white'); $wf_canvas->pack(-expand => 1, -fill => 'both', -side => 'left'); } } sub plotwave($) { my $len = shift; my $xscale = $mw->width() / $len; my @xy = (); my $i; foreach $i (0 .. ($len - 1)) { push @xy, $i * $xscale, 100 - sin(0.00001 * $i) * 100; } $wid = $wf_canvas->createLine(@xy, -fill => 'black', -joinstyle => ' +bevel'); my @bbox = $wf_canvas->bbox('all'); $wf_canvas->configure(-height => ($bbox[3] - $bbox[1]), -width => ($bbox[2] - $bbox[0])); return; } sub plotwave1() { wfplot_canvas() if ! Exists($wf_canvas); $wf_canvas->delete($wid) if $wid; plotwave(1048572); } sub plotwave2() { wfplot_canvas() if ! Exists($wf_canvas); $wf_canvas->delete($wid) if $wid; plotwave(1048573); }

In reply to Tk::Canvas->createLine max? by stead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.