Re: segmentation with Glib::RefPtr<Pixbuf>



oedipus <alexander arnoldt gmx de> writes:

> I am creating a pixelbuffer with Gdk::Pixbuf::create(...) an empty
> pixelbuffer and put in the pixelvalues later in some loops and than load up
> the created image in a Gtk::Image. So far it works fine, but when I want to
> write new data into the very same pixelbuffer my program crashes with a
> segmentation fault. I tried already the valgrind but couldn't realy get
> anything helpfull out of it. I append in the end the debug messages. 

I didn't look closely at your code, but have you double-checked that
you are not writing outside the valid pixel data area? That could
cause memory corruption, and memory corruption generally results in
weird, illogical behaviour.

BTW I have a couple of small helper classes for reading/writing pixels
in a pixbuf to make this simpler. It's as fast as doing the stuff by
hand. You can get it here:

  http://people.iola.dk/olau/misc/pixbuf-drawing.hpp

With it you can write

  PixelPosition p = get_position(pixbuf, x, y);

  p.left(3);             // move 3 pixels left
  p.up();                // move up 1 pixel
  p.pixel().red() = 132; // change pixel's red channel

There is also an iterator class for stuff like

  // set red channel in entire pixbuf
  for (PixelIterator i = begin(pixbuf), end = end(pixbuf); i != end; ++i)
    i->red() = 132;


-- 
Ole Laursen
http://people.iola.dk/olau/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]