# Wx::Bitmap causes segfaults

**URL:** <https://www.ruby-forum.com/t/wx-bitmap-causes-segfaults/150797>\
**Category:** wxRuby\
**Created:** [October 13, 2008, 1:43pm UTC](https://www.ruby-forum.com/t/wx-bitmap-causes-segfaults/150797 "2008-10-13T13:43:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![granden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@granden](https://www.ruby-forum.com/u/granden)\
**Post date:** [October 13, 2008, 1:43pm UTC](https://www.ruby-forum.com/t/wx-bitmap-causes-segfaults/150797/1 "2008-10-13T13:43:03Z")

</div>

Instantiating a Wx::Bitmap with width and height causes a segmentation  
fault. This is the minimal example I could find where the behaviour is  
exhibited:

require ‘rubygems’  
require ‘wx’  
Wx::Bitmap.new(1, 1)

Results in:  
/usr/lib/ruby/gems/1.8/gems/wxruby-1.9.8-x86-linux/lib/wx/classes/bitmap.rb:17:  
[BUG] Segmentation fault  
ruby 1.8.6 (2007-09-24) [i486-linux]

Note that without width and height, no segmentation fault is caused:

Wx::Bitmap.new // =\> #Wx::Bitmap:0xb5eef164

I’m running Ubuntu Hardy 8.04, ruby 1.8.6 (2007-09-24 patchlevel 111)  
[i486-linux], wxwidgets 1.9.6, and have the following wx-packages  
installed:

libwxbase2.6-0 2.6.3.2.2-2ubuntu4  
libwxbase2.8-0 2.8.7.1-0ubuntu3  
libwxbase2.8-dev 2.8.7.1-0ubuntu3  
libwxgtk2.6-0 2.6.3.2.2-2ubuntu4  
libwxgtk2.8-0 2.8.7.1-0ubuntu3  
libwxgtk2.8-dev 2.8.7.1-0ubuntu3  
wx2.8-headers 2.8.7.1-0ubuntu3

Any help is greatly appreciated!

- andreas

---

<div class="post-metadata">

**Author:** ![granden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@granden](https://www.ruby-forum.com/u/granden)\
**Post date:** [October 13, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/wx-bitmap-causes-segfaults/150797/2 "2008-10-13T16:20:53Z")

</div>

Andreas GarnÃ¦s wrote:

> I’m running Ubuntu Hardy 8.04, ruby 1.8.6 (2007-09-24 patchlevel 111)  
> [i486-linux], wxwidgets 1.9.6, and have the following wx-packages  
> installed: […]

Correction: I’m actually running wxwidgets 1.9.8.

---

<div class="post-metadata">

**Author:** ![granden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@granden](https://www.ruby-forum.com/u/granden)\
**Post date:** [October 25, 2008, 3:49pm UTC](https://www.ruby-forum.com/t/wx-bitmap-causes-segfaults/150797/3 "2008-10-25T15:49:22Z")

</div>

Hi Andreas

Sorry for the delay in replying.

Andreas Garnæs wrote:

> Instantiating a Wx::Bitmap with width and height causes a segmentation  
> fault. This is the minimal example I could find where the behaviour is  
> exhibited:
> 
> require ‘rubygems’  
> require ‘wx’  
> Wx::Bitmap.new(1, 1)

The problem here is not that Wx::Bitmap.new(width, height) segfault, but  
that you can’t instantiate Bitmap (or similarly, Font, I guess) outside  
of the main loop. In other words, you can’t call Bitmap.new until after  
you’ve called App.run or App.main\_loop. It works fine otherwise (tested  
SVN HEAD on GTK).

This restriction is inherited from Wx, unfortunately. Bitmap is a  
platform-specific representation of an image, and wraps a C++ native gui  
object. These can’t be created until various setup steps have been  
done.

The no-argument version is an exception because no real resource is  
created.

There are different ways round this - ArtProvider provides a way of  
retrieving and caching standard images.

Following this I’ve added a note to the documentation of Bitmap and Font  
to say they shouldn’t be created outside of main\_loop.

cheers  
alex
