Wx::Bitmap causes segfaults


#1

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

#2

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.


#3

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