[gnomemm] [canvas] deleting a C++ wrapper of a CanvasItem doesn't delete the item itself



It seems like there's some refcounting issue with Gnome::Canvas::Item and
its underlying GnomeCanvasItem that creates a dangling reference when the
C++ wrapper is deleted.
See the attached program for a test case.

-- 
   .--= ULLA! =---------------------.   `We are not here to give users what
   \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
    `---= cactus cactus rulez org =---'
'Criminal Lawyer' is a redundancy.
#include <libgnomecanvasmm/canvas.h>
#include <libgnomecanvasmm/item.h>
#include <libgnomecanvasmm/rect.h>
#include <libgnomecanvasmm/canvas-property.h>
#include <libgnomecanvasmm/init.h>

#include <gtkmm/window.h>

#include <glibmm/main.h>
#include <gtkmm/main.h>

#include <iostream>

class MyCanvas: public Gnome::Canvas::Canvas
{
    Gnome::Canvas::Rect *last_item;
public:
    MyCanvas () : last_item (0) {
	Glib::signal_timeout ().connect (SigC::slot (*this, &MyCanvas::timeout_cb), 500);
    }
    
private:
    bool timeout_cb () {
	std::cerr << "timeout_cb" << std::endl;

	if (last_item)
	    delete last_item;

	static int x1 = 0;
	static int y1 = 0;
	
	last_item = new Gnome::Canvas::Rect (*root (), x1, y1, x1 + 50, y1 + 50);
	using namespace Gnome::Canvas::Properties;
	*last_item << width_pixels (1) << outline_color ("black");
	
	x1 += 10;
	y1 += 10;
	
	return true;
    }
};

int main (int argc, char **argv)
{
    Gtk::Main m (argc, argv);
    Gnome::Canvas::init ();
    
    Gtk::Window w;
    MyCanvas c;
    w.add (c);
    w.show_all ();

    m.run ();
}


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