Glib: invalid unclassed type '(null)' in class cast

I have no idea what I’m doing wrong with my OpenMicNode type, its meant to be extended but the type itself is having issues. I’ve documented my findings on my GitHub issue: https://github.com/MidstallSoftware/openmic/issues/1. In case you don’t want to look, here’s the info. The program is segfaulting from not being able to attach a GNode from OpenMicNode to another. I believe that segfault is coming from these warnings

(openmic-cli:715331): GLib-GObject-WARNING **: 20:20:52.166: invalid unclassed type '(null)' in class cast to 'OpenMicNode'
(openmic-cli:715331): GLib-GObject-WARNING **: 20:20:52.166: invalid unclassed type '(null)' in class cast to 'OpenMicNode'
(openmic-cli:715331): GLib-GObject-WARNING **: 20:20:52.166: invalid unclassed type '(null)' in class cast to 'OpenMicNode'
(openmic-cli:715331): GLib-GObject-WARNING **: 20:20:52.166: invalid unclassed type '(null)' in class cast to 'OpenMicNode'

Those warnings are coming from src/lib/node.c (https://github.com/MidstallSoftware/openmic/blob/master/src/lib/node.c) but specfically with OPENMIC_NODE_CLASS being called outside of the object itself. The only class related function working is openmic_node_class_init. I have no idea what’s going wrong since I’ve never experienced this problem before so I’m asking here if someone knows what is wrong or if this is actually a bug with glib itself.

1 Like

Looking at src/lib/node.c#L19:

static void openmic_node_constructed(GObject* obj) {
	OpenMicNode* self = OPENMIC_NODE(obj);
	OpenMicNodeClass* klass = OPENMIC_NODE_CLASS(self); // FIXME: invalid unclassed type
	klass->gnode = g_node_new(self);

	G_OBJECT_CLASS(openmic_node_parent_class)->constructed(obj);
}

Maybe you could use OPENMIC_NODE_GET_CLASS instead of OPENMIC_NODE_CLASS. Though it might be better to move gnode to the OpenMicNodePrivate struct instead of the class struct.

So make GNode a property instead?

I don’t know what you intend with your code so I can’t say for sure, but it looks suspicious to me. Having it in the class struct means it will be shared by all OpenMicNode instances. You probably don’t want that.

Ah, and I’m guessing that applies to classes which extend OpenMicNode

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.