GooCanvas Reference Counting woes.



Hey,

I'm going through trying to finish these wrappers for GooCanvas and I'm having a heck of a time trying to get reference counting done correctly.

The most obvious case to point out is in the signal handlers.

From the reading I've been doing, it appears that when the signal is called, the Glib::RefPtr is done using ::wrap() which doesn't appear to increment the reference count.  But then at the end of the signal handler, when the RefPtr goes out of scope, the reference count is decremented, thus causing the object to be deleted.

The signal handler method looks like this:

bool
SimpleWindow::on_rect_button_press( const Glib::RefPtr<GooCanvas::ItemView>& item, GdkEventButton* event )
{
    std::cout << "You clicked the rectangle!" << std::endl ;
    item->reference() ;
    return true ;
}

By calling item->reference(), all problems are solved.

I tried changing the convert m4 macro to this:

_CONVERSION(`GooCanvasItemView*',`const Glib::RefPtr<ItemView>&',`Glib::wrap($3,true)')

So that the reference count would be updated, but it doesn't seem to affect anything.

Anyway, the current version in SVN has all this if anyone would like to take a look.

svn url: http://svn.gna.org/svn/libgoocanvasmm/trunk/libgoocanvasmm

Thanks,
Paul




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