[cairo] crasher
Øyvind Kolås
islewind at gmail.com
Sat Mar 19 16:15:19 PST 2005
On Sat, 19 Mar 2005 19:02:09 -0500, John McCutchan <ttb at tentacle.dhs.org> wrote:
> Yo,
>
> This simple program crashes cairo. Am I doing something wrong or what?
> /* snip */
> while (1) {
> cairo_scale (cr, 400, 16);
> cairo_set_line_width (cr, 0.04);
> cairo_move_to (cr, 0.0, 0.0);
> /* snip */
> cairo_close_path (cr);
> cairo_stroke (cr);
> }
> /* snip */
The reason this program crashes is that you are zooming in 400% , 16%
for each iteration, if your intention is just to repeatedly draw the
same figure, you would have to add a cairo_save(cr);
cairo_restore(cr); pair around the drawing commands.
/***********/
#include <cairo.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
int x, y, stride;
cairo_t *cr;
x = 400;
y = 400;
stride = x * 4;
cr = cairo_create ();
cairo_set_target_image (cr, (char *)malloc (sizeof(uint32_t) * x
* y), CAIRO_FORMAT_ARGB32, x, y, stride);
while (1) {
cairo_save (cr); /*< added */
cairo_scale (cr, 400, 16);
cairo_set_line_width (cr, 0.04);
cairo_move_to (cr, 0.0, 0.0);
cairo_line_to (cr, 1.0, 0.0);
cairo_line_to (cr, 1.0, 1.0);
cairo_line_to (cr, 0.0, 1.0);
cairo_save (cr);
cairo_set_rgb_color (cr, 0.3725, 0.5254,
0.7019);
cairo_fill (cr);
cairo_restore (cr);
cairo_close_path (cr);
cairo_stroke (cr);
cairo_restore (cr); /*< added */
}
}
/***********/
That program will happily run forever, and not fail due to allocation
of large amounts of temporary memory to create shapes many times
larger than the allocated buffer.
/Øyvind K.
--
Software patents hinder progress | http://swpat.ffii.org/
Web : http://pippin.gimp.org/
More information about the cairo
mailing list