# Segmentation fault

**URL:** <https://www.ruby-forum.com/t/segmentation-fault/192632>\
**Category:** wxRuby\
**Created:** [August 3, 2010, 1:25pm UTC](https://www.ruby-forum.com/t/segmentation-fault/192632 "2010-08-03T13:25:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_S\_Kerrie\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f05b48/32.png) [@Phillip\_S\_Kerrie\_Sh](https://www.ruby-forum.com/u/Phillip_S_Kerrie_Sh)\
**Post date:** [August 3, 2010, 1:25pm UTC](https://www.ruby-forum.com/t/segmentation-fault/192632/1 "2010-08-03T13:25:04Z")

</div>

Hi,  
Thank you for publishing WxRuby. I am enjoying the time spent learning  
how  
to use it.

I now have a 2000 line program that has found a bug in the sample  
printing.rb code and one in the WxRuby printing subsystem.

In the sample code for printing, svn - Revision 2112:  
/trunk/wxruby/samples/printing/printing.rb, the page one code does not  
scale  
the graphics to the printed page size. For an a4 page it is printed at  
the  
same scale as it appears on screen. And while it prints the second page  
okay  
it shows a blank page in the printpreview window.

The error is that the scaling code is using integer division instead of  
floating point division. The patch below fixes this bug.

## 274,275c274,275 \< scale\_x=(w/max\_x) \< scale\_y=(h/max\_y)

> ```
> scale_x=(w.to_f/max_x.to_f)
> scale_y=(h.to_f/max_y.to_f)
> 
> ```

## 321c321 \< overall\_scale = scale \* (w/page\_width)

> ```
> overall_scale = scale * (w.fdiv(page_width))
> 
> ```

The second bug is something that I can not fix. If I apply the following  
patch to printing.rb, ruby will fail with a segmentation fault as I  
dismiss  
the page setup dialog every time.

If I dont apply the patch, the segmentation fault will only appear when  
I  
exit the application. I would appreciate your response on this matter.

## 170c170 \< page\_setup\_dialog = Wx::PageSetupDialog.new(self, Wx::get\_app.page\_setup\_data)

> ```
> page_setup_dialog = Wx::PageSetupDialog.new(nil,
> 
> ```

Wx::get\_app.page\_setup\_data)  
174a175

> ```
> page_setup_dialog.destroy()
> 
> ```

I am using ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-mswin32] and  
A wxRuby distribution for Windows bundling :

- ruby-1.9.1-p243 with its minimal dependency (zlib, iconv) built with  
MinGW
- wxRuby-2.0.1
  - built with wxWidgets-2.8.10
  - associated documentation and samples

- ruby-opengl-0.60.1
- RMagick-2.11.0 built with ImageMagick-6.5.5-6 with PNG/JPEG/TIFF  
support

Phillip Shelton
