Segfault on mouseWatcher->has_mouse()

Hello, I am newbie in c++ and sorry my bad English. I Get Segmentation fault, when I tried to get mouse status from mouseWatcher.

code here:

Ubuntu 10.10 amd64, compiz, gnome.

Welcome to the forums! :slight_smile:

But seriously, it’s because you declared a mouseWatcher pointer but never assigned it to anything. So you’re trying to dereference an uninitialised pointer.

Thanks rdb, I add:

mouseWatcher=new MouseWatcher();

to main(), now I don’t have segfault, but mouseWatcher don’t react on mouse. I need to set mouseWatcher to watch window or something?
Sorry for newbie questions.

You need to use the existing MouseWatcher node, that you can retrieve by calling get_mouse().node() on the WindowFramework object.

I change to:

mouseWatcher = DCAST(MouseWatcher, window->get_mouse().node());

and now all works. Thank you rdb!