Thank you for reply.

The main reasons for cairo were to draw more interesting stuff than a red rectangle (which was used to make example code short) and to do it fast enough for a simple game.

Your code worked perfectly, but would you like to explain what is the reason for "no warnings", please? Everybody seems to be advocating for "use warnings".

I suddenly discovered SDL::GFX::Primitives namespace which looks suitable

Just in case, here are two pieces of code: Perl version segfaults and C one works. Either they are not equivalent or perl-cairo and perl-sdl are not compatible

use strict; no warnings; use SDL v2.3; use SDL::Video; use SDL::Surface; use Cairo; SDL::init(SDL_INIT_VIDEO); my $screen = SDL::Video::set_video_mode(400, 300, 32, SDL_SWSURFACE); SDL::Video::lock_surface($screen) if SDL::Video::MUSTLOCK($screen); my $surface = Cairo::ImageSurface->create_for_data ( $screen->get_pixels_ptr, 'argb32', $screen->w, $screen->h, $screen->pitch ); my $cr = Cairo::Context->create($surface); $cr->rectangle(10, 10, 40, 40); $cr->set_source_rgb(255, 0, 0); $cr->fill; SDL::Video::unlock_surface($screen) if SDL::Video::MUSTLOCK($screen); SDL::Video::flip($screen); SDL::delay(2000); SDL::quit();

#include <SDL.h> #include <cairo.h> int main () { SDL_Init(SDL_INIT_VIDEO); SDL_Surface *screen = SDL_SetVideoMode(400, 300, 32, SDL_SWSURFACE); if (SDL_MUSTLOCK(screen)) { SDL_LockSurface(screen); } cairo_surface_t *cairosurf = cairo_image_surface_create_for_data ( screen->pixels, CAIRO_FORMAT_ARGB32, screen->w, screen->h, screen->pitch ); cairo_t *cr = cairo_create(cairosurf); cairo_rectangle(cr, 10, 10, 40, 40); cairo_set_source_rgb(cr, 255, 0, 0); cairo_fill(cr); if (SDL_MUSTLOCK(screen)) { SDL_UnlockSurface(screen); } SDL_Flip(screen); SDL_Delay(2000); SDL_Quit(); return 0; }

In reply to Re^2: SDL and Cairo segfault by Atacama
in thread SDL and Cairo segfault by Atacama

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.