problems with singleton in GObject



[PS.: I don't know if this is the right list for this kind of message,
so just point me to the right one.]

Hi,

I'm writing a plugin for Cairo Composite Manager and I'm implementing
my own constructor method, since I'd like only one instance, so I
follow what is said about the singleton pattern in:
http://library.gnome.org/devel/gobject/stable/gobject-The-Base-Object-Type.html

The problem is that when I execute the code I get the following
CRITICAL warning:

** (cairo-compmgr:13542): CRITICAL **: ccm_window_plugin_paint:
assertion `CCM_IS_WINDOW_PLUGIN (self)' failed

My constructor is as follow:

static GObject*
ccm_magnifier_constructor (GType type, guint n_construct_params,
						   GObjectConstructParam *construct_params)
{
	GObject *object;

	if (!ccm_magnifier_singleton) {
		CCMPluginClass *klass;
		GObjectClass *parent_class;
		klass = CCM_MAGNIFIER_CLASS (g_type_class_peek (CCM_TYPE_MAGNIFIER));
		parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
		object = parent_class->constructor (type,
											n_construct_params,
											construct_params);
		ccm_magnifier_singleton = CCM_MAGNIFIER (object);
	} else
		object = G_OBJECT (g_object_ref (G_OBJECT (ccm_magnifier_singleton)));
	
	return object;
}

If I don't override the constructor or change it to something like it
(what I think that is the same behaviour of a non-override constructor
method :):

static GObject*
ccm_magnifier_constructor (GType type, guint n_construct_params,
						   GObjectConstructParam *construct_params)
{
	GObject *object;

	CCMPluginClass *klass;
	GObjectClass *parent_class;
	klass = CCM_MAGNIFIER_CLASS (g_type_class_peek (CCM_TYPE_MAGNIFIER));
	parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
	object = parent_class->constructor (type,
										n_construct_params,
										construct_params);
	return object;
}

it's works.

I read the GObject documentation available in library.gnome.org, but
doesn't find any reason for the behaviour that is giving me the
CRITICAL message. If someone can help me I will be very grateful.

Thanks,
Carlos.


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