c++gtkmmcoredumpgtksourceview

Gsv::buffer error


In my c++ project, I want to use a Gsv::buffer from GTKsourceview library. I declare my buffer like this:

Glib::RefPtr<Gsv::Buffer> buffer;

I create it :

buffer->create();

But when I want to use some inherited fonction from Gtk::buffer:

 buffer->set_text("somethings");

The executable exit and return:

Erreur de segmentation (core dumped)

What is the problem?

Thanks for your help


Solution

  • You create a pointer, but you don't actually make it point anywhere. In essence, buffer is a null pointer.

    From the RefPtr default constructor refernece:

    Afterwards it will be null and use of -> will cause a segmentation fault.

    You need to explicitly create the object pointed to, using the static Gsv::Buffer::create function, like e.g.

    Glib::RefPtr<Gsv::Buffer> buffer = Gsv::Buffer::create();