[wxruby-users] Wx::Bitmap causes segfaults
Alex Fenton
alex at pressure.to
Sat Oct 25 09:34:17 EDT 2008
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
More information about the wxruby-users
mailing list