Hi.

I'm trying to get SDL and Cairo working together using the code below.

I expect Cairo to draw a red square inside the SDL window.

The program segfaults instead.

This page cairographics.org/SDL says that libraries should work fine together if they "agree on the pixel format"

I tried to change pixel format to 24/rgb24 and other permutations of available formats without success.

Am I missing something?

Thank you for your time.

use strict; use warnings; use SDL v2.3; use SDL::Video; use SDL::Event; use SDL::Events; use SDL::Surface; use Cairo; my $WIDTH = 400; my $HEIGHT = 300; # relevant part starts: my $screen = SDL::Video::set_video_mode($WIDTH, $HEIGHT, 32, SDL_SWSUR +FACE); SDL::Video::lock_surface($screen); my $surface = Cairo::ImageSurface->create_for_data ( $screen->get_pixels_ptr, 'argb32', $screen->w, $screen->h, $screen->pitch ); my $cairo = Cairo::Context->create($surface); $cairo->rectangle(0, 0, 100, 100); $cairo->set_source_rgb(255, 0, 0); $cairo->fill; SDL::Video::unlock_surface($screen); SDL::Video::update_rect($screen, 0, 0, $WIDTH, $HEIGHT); # relevant part ends LOOP: while (1) { my $event = SDL::Event->new(); while (SDL::Events::poll_event($event)) { last LOOP if $event->type == SDL_KEYDOWN || $event->type == SDL_QUIT; } SDL::Events::pump_events(); } SDL::quit;

In reply to 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.