c - Segmentation Fault GTK+ application -
i'm making gtk 3+ application using glade. here structure in c :
# include <gtk/gtk.h> # include <stdio.h> # include <stdlib.h> typedef struct s_gtk { gtkbuilder *interface; gtkwidget *mainwindow; gtkwidget *addobject; gtkwidget *deleteobject; gtkwidget *launch; gerror *error; gchar *filename; } t_gtk;
my function intializing gtk->addobject, called in main :
if ((gtk->interface = gtk_builder_new()) == null || (gtk->filename = g_build_filename("interface.glade", null)) == null) { g_error("%s", gtk->error->message); g_error_free(gtk->error); return (gtk->error->code); } gtk_builder_add_from_file(gtk->interface, gtk->filename, >k->error); g_free(gtk->filename); if (gtk->error) { g_printerr("%s\n", gtk->error->message); g_error_free(gtk->error); return (gtk->error->code); } gtk->mainwindow = gtk_widget(gtk_builder_get_object (gtk->interface, "mainwindow")); gtk->addobject = gtk_widget(gtk_builder_get_object (gtk->interface, "adddialog")); gtk_builder_connect_signals(gtk->interface, gtk); return (0);
my handler addobject:
void on_addobject_clicked(gpointer user_data) { t_gtk *gtk; gint response; gtk = (t_gtk *)user_data; printf("i'm here\n"); response = gtk_dialog_run(gtk_dialog(gtk->addobject)); printf("i'm here2\n"); if (response == 1) { printf("add pressed!\n"); } else { printf("cancel pressed!\n"); } gtk_widget_hide(gtk->addobject); }
and segfault here don't know why...:
response = gtk_dialog_run(gtk_dialog(gtk->addobject));
valgrind says it:
invalid read of size 8 ==7272== @ 0x6b16620: g_type_check_instance_cast (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x401063: on_addobject_clicked (in /home/vives_j/documents/epitech/tests/main) ==7272== 0x6af3473: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d086: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d9de: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x4f3ca1c: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1400.5) ==7272== 0x4f3ca74: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1400.5) ==7272== 0x6af3473: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d086: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d9de: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x4f3a9ff: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1400.5) ==7272== 0xb795dbf: ffi_call_unix64 (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.2) ==7272== address 0x400000003 not stack'd, malloc'd or (recently) free'd ==7272== ==7272== ==7272== process terminating default action of signal 11 (sigsegv) ==7272== access not within mapped region @ address 0x400000003 ==7272== @ 0x6b16620: g_type_check_instance_cast (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x401063: on_addobject_clicked (in /home/vives_j/documents/epitech/tests/main) ==7272== 0x6af3473: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d086: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d9de: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x4f3ca1c: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1400.5) ==7272== 0x4f3ca74: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1400.5) ==7272== 0x6af3473: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d086: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x6b0d9de: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4200.1) ==7272== 0x4f3a9ff: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.1400.5) ==7272== 0xb795dbf: ffi_call_unix64 (in /usr/lib/x86_64-linux-gnu/libffi.so.6.0.2) ==7272== if believe happened result of stack ==7272== overflow in program's main thread (unlikely ==7272== possible), can try increase size of ==7272== main thread stack using --main-stacksize= flag. ==7272== main thread stack size used in run 8388608.
and compile (from make command):
gcc -wextra -wall -ansi -pedantic -i. -o3 -d reentrant -rdynamic -dgtk_disable_deprecated=1 -dgdk_disable_deprecated -dgdk_pixbuf_disable_deprecated -dg_disable_deprecated -dgtk_multihead_safe=1 -dgtk_multidevice_safe=1 `pkg-config gmodule-export-2.0 --libs` `pkg-config gtk+-3.0 --cflags` -c -o main.o main.c gcc main.o -o main `pkg-config gtk+-3.0 --libs` `pkg-config gmodule-export-2.0 --libs`
gdb results :
gnu gdb (debian 7.7.1+dfsg-5) 7.7.1 copyright (c) 2014 free software foundation, inc. license gplv3+: gnu gpl version 3 or later <http://gnu.org/licenses/gpl.html> free software: free change , redistribute it. there no warranty, extent permitted law. type "show copying" , "show warranty" details. gdb configured "x86_64-linux-gnu". type "show configuration" configuration details. bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. find gdb manual , other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. help, type "help". type "apropos word" search commands related "word"... reading symbols ./main...done. (gdb) (gdb) run starting program: /home/vives_j/documents/epitech/tests/main [thread debugging using libthread_db enabled] using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". (process:3752): gtk-warning **: locale not supported c library. using fallback 'c' locale. [new thread 0x7fffee33c700 (lwp 3756)] [new thread 0x7fffedb3b700 (lwp 3757)] [new thread 0x7fffecfe7700 (lwp 3759)] i'm here program received signal sigsegv, segmentation fault. 0x00007ffff5f0f620 in g_type_check_instance_cast () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (gdb) backtrac #0 0x00007ffff5f0f620 in g_type_check_instance_cast () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #1 0x0000000000401034 in on_addobject_clicked (user_data=0x8d0350) @ main.c:57 #2 0x00007ffff5eec474 in ?? () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #3 0x00007ffff5f06087 in g_signal_emit_valist () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #4 0x00007ffff5f069df in g_signal_emit () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #5 0x00007ffff762ca1d in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #6 0x00007ffff762ca75 in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #7 0x00007ffff5eec474 in ?? () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #8 0x00007ffff5f06087 in g_signal_emit_valist () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #9 0x00007ffff5f069df in g_signal_emit () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #10 0x00007ffff762aa00 in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #11 0x00007ffff127edc0 in ffi_call_unix64 () /usr/lib/x86_64-linux-gnu/libffi.so.6 #12 0x00007ffff127e828 in ffi_call () /usr/lib/x86_64-linux-gnu/libffi.so.6 ---type <return> continue, or q <return> quit--- #13 0x00007ffff5eecebc in g_cclosure_marshal_generic_va () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #14 0x00007ffff5eec474 in ?? () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #15 0x00007ffff5f06087 in g_signal_emit_valist () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #16 0x00007ffff5f069df in g_signal_emit () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #17 0x00007ffff76cf191 in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #18 0x00007ffff5eef233 in g_cclosure_marshal_void__boxedv () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #19 0x00007ffff5eec474 in ?? () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #20 0x00007ffff5f06087 in g_signal_emit_valist () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #21 0x00007ffff5f069df in g_signal_emit () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #22 0x00007ffff76cc94e in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #23 0x00007ffff76cdd9b in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #24 0x00007ffff76d05e0 in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #25 0x00007ffff76a3e7b in gtk_event_controller_handle_event () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #26 0x00007ffff783f41d in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 ---type <return> continue, or q <return> quit--- #27 0x00007ffff771241e in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #28 0x00007ffff5eec474 in ?? () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #29 0x00007ffff5f05b30 in g_signal_emit_valist () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #30 0x00007ffff5f069df in g_signal_emit () /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #31 0x00007ffff7842de4 in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #32 0x00007ffff770fd2e in ?? () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #33 0x00007ffff771193e in gtk_main_do_event () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #34 0x00007ffff72b8b12 in ?? () /usr/lib/x86_64-linux-gnu/libgdk-3.so.0 #35 0x00007ffff5c16c5d in g_main_context_dispatch () /lib/x86_64-linux-gnu/libglib-2.0.so.0 #36 0x00007ffff5c16f48 in ?? () /lib/x86_64-linux-gnu/libglib-2.0.so.0 #37 0x00007ffff5c17272 in g_main_loop_run () /lib/x86_64-linux-gnu/libglib-2.0.so.0 #38 0x00007ffff7710bf5 in gtk_main () /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 #39 0x0000000000401275 in main (ac=1, av=0x7fffffffdcf8) @ main.c:115 (gdb) quit
the line 57 line posted crashed.
glade file : http://pastebin.com/jrhza6iw think have clue. because, when took example code tutorial : http://pastebin.com/wpj6kwqb , compiled (and builder file):
gcc -o dialog1 dialog1.c $(pkg-config --cflags --libs gtk+-2.0 \ * gmodule-export-2.0)
it works, if change gtk+-2.0 3.0, crashes @ same thing. thank in advance !!
i found problem. in handler function, need pass in parameter type of widget clicked. here, it's gtkbutton, added in parameters receive :
void on_addobject_clicked(gtkbutton *button, gpointer user_data) { t_gtk *gtk; gint response; gtk = (t_gtk *)user_data; (void) button; printf("i'm here\n"); response = gtk_dialog_run(gtk_dialog(gtk->addobject)); printf("i'm here2\n"); if (response == 1) { printf("add pressed!\n"); } else { printf("cancel pressed!\n"); } gtk_widget_hide(gtk->addobject); }
i think gtk needs in background. it's resolved. thank anyway ! :)
Comments
Post a Comment