# \[BUG\] Segmentation fault if using PrintOperation for the sec

**URL:** <https://www.ruby-forum.com/t/bug-segmentation-fault-if-using-printoperation-for-the-sec/77236>\
**Category:** Ruby-Gnome 2\
**Created:** [November 25, 2006, 10:14am UTC](https://www.ruby-forum.com/t/bug-segmentation-fault-if-using-printoperation-for-the-sec/77236 "2006-11-25T10:14:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 25, 2006, 10:14am UTC](https://www.ruby-forum.com/t/bug-segmentation-fault-if-using-printoperation-for-the-sec/77236/1 "2006-11-25T10:14:37Z")

</div>

Hi,

i attach a script, which sets page setup(this may not be necessary for  
the bug to appear), and then enters a loop in which it calls  
PrintOperation.run until it segfault.  
the script generates a 61 page empty print context.

this is the output:  
./printer3.rb:25: [BUG] Segmentation fault  
ruby 1.8.5 (2006-08-25) [i686-linux]

this script is a simplified version of my print-testing script, in which  
i noticed this error, i use cairo there, and thus get cairo error on  
this same segfault:

/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb: line 27  
Gtk-CRITICAL \*\*:gtk\_print\_operation\_preview\_render\_page: assertion  
`GTK_IS_PRINT_OPERATION_PREVIEW (preview)' failed ruby: cairo-surface.c:437: cairo_surface_destroy: Assertion`surface-\>ref\_count \> 0’ failed.  
Aborted

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 26, 2006, 10:36am UTC](https://www.ruby-forum.com/t/bug-segmentation-fault-if-using-printoperation-for-the-sec/77236/2 "2006-11-26T10:36:32Z")

</div>

Hi,

# This seems a problem of GTK+, not Ruby/GTK.

# I reported this to [bugzilla.gnome.org](http://bugzilla.gnome.org).

## The smallest sample to reproduce your problem is:

require ‘gtk2’

## printo = Gtk::PrintOperation.new printo.set\_n\_pages(1) printo.run(Gtk::PrintOperation::ACTION\_PRINT\_DIALOG, nil) printo.run(Gtk::PrintOperation::ACTION\_PRINT\_DIALOG, nil)

## And the equivalent source in C is:

#include \<gtk/gtk.h\>

int main(int argc, char\*\* argv){  
GtkPrintOperation\* op;  
GError\* error = NULL;

gtk\_init(&argc, &argv);

## op = gtk\_print\_operation\_new(); gtk\_print\_operation\_set\_n\_pages(op, 1); gtk\_print\_operation\_run(op, GTK\_PRINT\_OPERATION\_ACTION\_PRINT\_DIALOG, NULL, &error); gtk\_print\_operation\_run(op, GTK\_PRINT\_OPERATION\_ACTION\_PRINT\_DIALOG, NULL, &error); return 0; }

You can compile this like as:  
gcc -o test `pkg-config gtk+-unix-print-2.0 --libs --cflags` test.c

And it has same problem. The result of gdb is:

Program received signal SIGSEGV, Segmentation fault.  
[Switching to Thread 46912496299600 (LWP 13655)]  
0x000000394bd5d5c5 in gtk\_print\_operation\_preview\_render\_page ()  
from /usr/lib64/libgtk-x11-2.0.so.0  
(gdb) bt  
#0 0x000000394bd5d5c5 in gtk\_print\_operation\_preview\_render\_page ()  
from /usr/lib64/libgtk-x11-2.0.so.0  
#1 0x000000394bd5ce96 in gtk\_print\_operation\_new ()  
from /usr/lib64/libgtk-x11-2.0.so.0  
#2 0x0000003f81a2cf44 in g\_main\_context\_dispatch ()  
from /lib64/libglib-2.0.so.0  
#3 0x0000003f81a2fd7d in g\_main\_context\_check () from  
/lib64/libglib-2.0.so.0  
#4 0x0000003f81a3008a in g\_main\_loop\_run () from  
/lib64/libglib-2.0.so.0  
#5 0x000000394bd5acbe in gtk\_print\_context\_get\_cairo\_context ()  
from /usr/lib64/libgtk-x11-2.0.so.0  
#6 0x000000394bd5b59f in gtk\_print\_operation\_run ()  
from /usr/lib64/libgtk-x11-2.0.so.0  
#7 0x00000000004007b1 in main ()

On Sat, 25 Nov 2006 11:12:37 +0200  
Dobai-Pataky BÃ¡lint [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Aborted

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
