[fpc-pascal] TOpenGLControl segfaults on re-parenting
denisgolovan
denisgolovan at yandex.ru
Sat Apr 6 21:38:14 CEST 2019
Some more information on the matter.
While investigating the issue I noticed that gtk_gl_area_destroy is called twice for single OpenGL widget when changing Parent property.
That does not look nice as it accesses freed memory second time it calls gdk_gl_context_unref (context : PGdkGLContextPrivate).
gtk2proc.DestroyWidget->gtk_widget_destroy calls gtk_gl_area_destroy twice via internal gtk/glib functions.
First time gtk_gl_area_destroy is called from g_object_run_dispose with following stack:
#0 GDK_GL_CONTEXT_UNREF(0x29451c0) at ../../../../../usr/local/share/lazarus/components/opengl/glgtkglxcontext.pas:456
#1 GTK_GL_AREA_DESTROY(0x278bb10) at ../../../../../usr/local/share/lazarus/components/opengl/glgtkglxcontext.pas:283
#2 g_closure_invoke(0x26f86b0, 0x26f86b0, 0x0, 0x0, 1, 0x7fffffffc4a0, 0x7fffffffc4a0, 0x7fffffffc410, 0x7fffffffc410) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gclosure.c:804
#3 signal_emit_unlocked_R(0x26f80a0, 0x26f80a0, 0, 0, 0x278bb10, 0x278bb10, 0x0, 0x0, 0x7fffffffc4a0, 0x7fffffffc4a0) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gsignal.c:3751
#4 g_signal_emit_valist(<optimized out>, <optimized out>, <optimized out>, 0x7fffffffc650, 0x7fffffffc650) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gsignal.c:3391
#5 g_signal_emit(<optimized out>, <optimized out>, <optimized out>) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gsignal.c:3447
#6 ?? at :0
#7 g_object_run_dispose(0x278bb10) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gobject.c:1084
#8 DESTROYWIDGET(0x278bb10) at gtk2/gtk2proc.inc:4252
#9 DESTROYCONNECTEDWIDGET(0x26a1100, 0x278bb10, false) at gtk2/gtk2widgetset.inc:4814
#10 DESTROYLCLCOMPONENT(0x26a1100, 0x2932a60) at gtk2/gtk2widgetset.inc:4724
#11 DESTROYHANDLE(0x2234978, 0x2932a60) at gtk2/gtk2wscontrols.pp:611
#12 DESTROYHANDLE(0x278be00, 0x2932a60) at ../../../../../usr/local/share/lazarus/components/opengl/openglcontext.pas:766
#13 DESTROYWND(0x2932a60) at include/wincontrol.inc:7869
#14 DESTROYHANDLE(0x2932a60) at include/wincontrol.inc:5321
#15 REMOVECONTROL(0x2907120, 0x2932a60) at include/wincontrol.inc:6374
#16 SETPARENT(0x2932a60, 0x2f8e840) at include/control.inc:4347
Second time - from g_object_unref with stack:
#0 GDK_GL_CONTEXT_UNREF(0x29451c0) at ../../../../../usr/local/share/lazarus/components/opengl/glgtkglxcontext.pas:449
#1 GTK_GL_AREA_DESTROY(0x278bb10) at ../../../../../usr/local/share/lazarus/components/opengl/glgtkglxcontext.pas:283
#2 g_closure_invoke(0x26f86b0, 0x26f86b0, 0x0, 0x0, 1, 0x7fffffffc480, 0x7fffffffc480, 0x7fffffffc3f0, 0x7fffffffc3f0) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gclosure.c:804
#3 signal_emit_unlocked_R(0x26f80a0, 0x26f80a0, 0, 0, 0x278bb10, 0x278bb10, 0x0, 0x0, 0x7fffffffc480, 0x7fffffffc480) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gsignal.c:3751
#4 g_signal_emit_valist(<optimized out>, <optimized out>, <optimized out>, 0x7fffffffc630, 0x7fffffffc630) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gsignal.c:3391
#5 g_signal_emit(<optimized out>, <optimized out>, <optimized out>) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gsignal.c:3447
#6 ?? at :0
#7 g_object_unref(0x278bb10) at /var/tmp/paludis/dev-libs-glib-2.52.3/work/glib-2.52.3/gobject/gobject.c:3148
#8 DESTROYWIDGET(0x278bb10) at gtk2/gtk2proc.inc:4252
#9 DESTROYCONNECTEDWIDGET(0x26a1100, 0x278bb10, false) at gtk2/gtk2widgetset.inc:4814
#10 DESTROYLCLCOMPONENT(0x26a1100, 0x2932a60) at gtk2/gtk2widgetset.inc:4724
#11 DESTROYHANDLE(0x2234978, 0x2932a60) at gtk2/gtk2wscontrols.pp:611
#12 DESTROYHANDLE(0x278be00, 0x2932a60) at ../../../../../usr/local/share/lazarus/components/opengl/openglcontext.pas:766
#13 DESTROYWND(0x2932a60) at include/wincontrol.inc:7869
#14 DESTROYHANDLE(0x2932a60) at include/wincontrol.inc:5321
#15 REMOVECONTROL(0x2907120, 0x2932a60) at include/wincontrol.inc:6374
#16 SETPARENT(0x2932a60, 0x2f8e840) at include/control.inc:4347
I guess I need some help from Lazarus GTK/GLib experts.
Calling glXDestroyContext in TOpenGLControl twice is obviously an undefined behavior and should be fixed.
--
Regards,
Denis Golovan
More information about the fpc-pascal
mailing list