App crash issue while selecting the text in gtk entry

Hello everyone,
I am using gtk4. I got an issue while selecting the text in the entry. The Issue is, when I select the text in the entry and srolled the window the app crashes and some times if I click on the selected text multiple times, the application is getting crashed with following criticals and warnings.

**(application:155158): GLib-GObject-WARNING **: 02:33:03.114: instance with invalid (NULL) class pointer**

**(application:155158): GLib-GObject-CRITICAL **: 02:33:03.115: g_signal_emit_valist: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed**

Here I am attaching the sample application

#include <gtk/gtk.h>

GtkWidget *entry[15];
GtkEntryBuffer *buffer[15];
GtkWidget *window;

static void activate(GtkApplication *app, gpointer user_data) {
    window = gtk_application_window_new(app);
    gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
    gtk_window_set_default_size(GTK_WINDOW(window), 500, 800);

    GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
    gtk_window_set_child(GTK_WINDOW(window), box);

    GtkWidget *scrolled_window = gtk_scrolled_window_new();
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_EXTERNAL);
    gtk_widget_set_size_request(scrolled_window, 400, 750);
    gtk_widget_set_margin_start(scrolled_window, 40);
    gtk_widget_set_margin_end(scrolled_window, 40);
   gtk_box_append(GTK_BOX(box), scrolled_window);

    GtkWidget *s_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);

    gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled_window), s_vbox);

    for (int i = 0; i < 15; i++) {
        buffer[i] = gtk_entry_buffer_new("Initial Text", -1);
        entry[i] = gtk_entry_new_with_buffer(buffer[i]);
        gtk_widget_set_size_request(entry[i], 396, 60);
        gtk_box_append(GTK_BOX(s_vbox), entry[i]);
        g_print("Created entry %d\n", i);
    }

    gtk_window_present(GTK_WINDOW(window));
}

int main(int argc, char *argv[]) {
    GtkApplication *app = gtk_application_new("com.example.GtkMultipleEntries", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    int status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return status;
}

I’m facing this issue with touch enabled devices and get the gdb logs as follows

(application:24665): GLib-GObject-WARNING **: 07:55:16.461: instance with invalid (NULL) class pointer
(application:24665): GLib-GObject-CRITICAL **: 07:55:16.461: g_signal_emit_valist: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
Thread 1 "application" received signal SIGSEGV, Segmentation fault.
 
0x0000fffff7910c28 in ?? () from /usr/lib/libgtk-4.so.1
 
(gdb) bt
 
#0  0x0000fffff7910c28 in ?? () from /usr/lib/libgtk-4.so.1
 
#1  0x0000fffff7910e44 in ?? () from /usr/lib/libgtk-4.so.1
 
#2  0x0000fffff79115cc in gtk_gesture_set_sequence_state () from /usr/lib/libgtk-4.so.1
 
#3  0x0000fffff7aa9650 in ?? () from /usr/lib/libgtk-4.so.1
 
#4  0x0000fffff7aae74c in ?? () from /usr/lib/libgtk-4.so.1
 
#5  0x0000fffff7911554 in gtk_gesture_set_sequence_state () from /usr/lib/libgtk-4.so.1
 
#6  0x0000fffff79116c8 in gtk_gesture_set_state () from /usr/lib/libgtk-4.so.1
 
#7  0x0000fffff7a2aa14 in ?? () from /usr/lib/libgtk-4.so.1
 
#8  0x0000fffff7820b88 in ?? () from /usr/lib/libgtk-4.so.1
 
#9  0x0000fffff7177eb0 in ?? () from /usr/lib/libgobject-2.0.so.0
 
#10 0x0000fffff7192d80 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
 
#11 0x0000fffff7192ff4 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
 
#12 0x0000fffff717b4ac in g_cclosure_marshal_VOID__BOXEDv () from /usr/lib/libgobject-2.0.so.0
 
#13 0x0000fffff7176034 in ?? () from /usr/lib/libgobject-2.0.so.0
 
#14 0x0000fffff7177eb0 in ?? () from /usr/lib/libgobject-2.0.so.0
 
#15 0x0000fffff7192d80 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
 
#16 0x0000fffff7192ff4 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
 
#17 0x0000fffff7910f0c in ?? () from /usr/lib/libgtk-4.so.1
 
#18 0x0000fffff7912b24 in ?? () from /usr/lib/libgtk-4.so.1
 
#19 0x0000fffff7916988 in ?? () from /usr/lib/libgtk-4.so.1
 
#20 0x0000fffff78dcbfc in ?? () from /usr/lib/libgtk-4.so.1
 
#21 0x0000fffff7aa1480 in ?? () from /usr/lib/libgtk-4.so.1
 
#22 0x0000fffff7aa9da8 in ?? () from /usr/lib/libgtk-4.so.1
 
#23 0x0000fffff796a224 in ?? () from /usr/lib/libgtk-4.so.1
 
#24 0x0000fffff796aa3c in ?? () from /usr/lib/libgtk-4.so.1
 
#25 0x0000fffff7ab6d34 in ?? () from /usr/lib/libgtk-4.so.1
 
#26 0x0000fffff7bb7618 in ?? () from /usr/lib/libgtk-4.so.1
 
#27 0x0000fffff7be88ec in ?? () from /usr/lib/libgtk-4.so.1
 
#28 0x0000fffff7177eb0 in ?? () from /usr/lib/libgobject-2.0.so.0
 
#29 0x0000fffff7192250 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
 
#30 0x0000fffff7192ff4 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
 
#31 0x0000fffff7becc54 in ?? () from /usr/lib/libgtk-4.so.1
 
#32 0x0000fffff7c00774 in ?? () from /usr/lib/libgtk-4.so.1
 
#33 0x0000fffff7057b38 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
 
#34 0x0000fffff7057dd8 in ?? () from /usr/lib/libglib-2.0.so.0
 
#35 0x0000fffff7057eac in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
 
#36 0x0000fffff72e0800 in g_application_run () from /usr/lib/libgio-2.0.so.0
 
#37 0x0000aaaaaaaa10ac in main ()

could anyone solve this issue, any suggestions are appreciated thanks in advance.

Hi,
Which exact versions of glib / gtk?
Which distribution ? display server?

Can you install gtk’s debuginfos for better gdb logs?

Hi gwillems,
Thanks for your reply.
I’m using yocto build distribution and Weston wayland display server. The exact versions of glib and gtk are glib-2.0_2.72.3 and gtk-4.6.2 respectively.

GTK 4.6 is a release from 4 years ago. You will not be able to get any support for that. The latest stable release is GTK 4.18.

You will need to ask on a Yocto support channel how to get a backtrace with full debugging symbols; but any debugging will have to be done on your side, because you’re using an unsupported release.

Ok, I’m trying to update GTK version to 4.18.
But with the same GTK version(4.6.2) and with same sample application, If I run the application with GSK_RENDERER=cairo ./application
I’m not facing this issue frequently(but occurring rarely). And I’m not facing App crash issue in touch laptops but facing in the yocto.

That probably means the issue is outside of gtk. Perhaps in libinput or weston.

Gtk-4.6 is quite old, and I suppose the other dependencies in your Yocto build are as much old too… I would not recommend to start new development on such obsolete platform.

If you have no choice but to use it, please try to install the debug symbols so the gdb trace can be decoded.

Are the debug symbols specific to GTK? How do I install them?

I don’t know how to do that on Yocto… Better ask on a Yocto support forum.

In general, some distributions offer the debug symbols as a separate package to install. If not, you may have to recompile gtk in debug mode.