Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault on first search after startup #154

Open
benaryorg opened this issue Oct 11, 2024 · 5 comments
Open

segfault on first search after startup #154

benaryorg opened this issue Oct 11, 2024 · 5 comments

Comments

@benaryorg
Copy link

benaryorg commented Oct 11, 2024

It seems that starting ahoviewer (built from 7a5b88f) and then searching on danbooru with a single term (e.g. listening_to_music) will sometimes crash ahoviewer.

Basically what I'm doing is:

  1. open ahoviewer
  2. search for a single term (e.g. listening_to_music) on danbooru
  3. if ahoviewer is still running wait for images to be fully loaded and then exit and goto 1.
stacktrace
0x00007ffff66f071f in gst_element_set_state () from /nix/store/vcs2n7d80s8qqk8zbq6dhzcp5cfsmpqq-gstreamer-1.24.3/lib/libgstreamer-1.0.so.0
(gdb) bt
#0  0x00007ffff66f071f in gst_element_set_state () from /nix/store/vcs2n7d80s8qqk8zbq6dhzcp5cfsmpqq-gstreamer-1.24.3/lib/libgstreamer-1.0.so.0
#1  0x00000000005816b2 in AhoViewer::VideoBox::reset_gstreamer_pipeline() ()
#2  0x00000000005818c5 in AhoViewer::VideoBox::hide() ()
#3  0x00000000005254bf in AhoViewer::ImageBox::clear_image() ()
#4  0x000000000054da54 in AhoViewer::MainWindow::on_imagelist_cleared() ()
#5  0x00000000005507f8 in sigc::internal::slot_call<AhoViewer::MainWindow::MainWindow(_GtkApplicationWindow*, Glib::RefPtr<Gtk::Builder> const&)::{lambda(AhoViewer::Booru::Page*)#1}, void, AhoViewer::Booru::Page*>::call_it(sigc::internal::slot_rep*, AhoViewer::Booru::Page* const&) ()
#6  0x00000000004ce3ed in sigc::internal::signal_emit1<void, AhoViewer::Booru::Page*, sigc::nil>::emit(sigc::internal::signal_impl*, AhoViewer::Booru::Page* const&) ()
#7  0x00000000004c7d54 in AhoViewer::Booru::Browser::on_switch_page(Gtk::Widget*, unsigned int) ()
#8  0x00007ffff79b838c in (anonymous namespace)::Notebook_signal_switch_page_callback(_GtkNotebook*, _GtkWidget*, unsigned int, void*) ()
   from /nix/store/0mx92yr40g5cakb5q52cr5adxfcxs9x4-gtkmm-3.24.9/lib/libgtkmm-3.0.so.1
#9  0x00007ffff7eda668 in g_closure_invoke () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#10 0x00007ffff7eeef39 in signal_emit_unlocked_R.isra.0 () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#11 0x00007ffff7ef0561 in signal_emit_valist_unlocked () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#12 0x00007ffff7ef62c2 in g_signal_emit_valist () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#13 0x00007ffff7ef636f in g_signal_emit () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#14 0x00007ffff6c32da1 in gtk_notebook_real_insert_page () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#15 0x00000000004c1b9a in AhoViewer::Booru::Browser::on_new_tab() ()
#16 0x00000000004c4400 in AhoViewer::Booru::Browser::search(bool) ()
#17 0x00000000004c5d5e in AhoViewer::Booru::Browser::on_entry_key_press_event(_GdkEventKey*) ()
#18 0x00007ffff7a19680 in (anonymous namespace)::Widget_signal_event_callback(_GtkWidget*, _GdkEvent*, void*) ()
   from /nix/store/0mx92yr40g5cakb5q52cr5adxfcxs9x4-gtkmm-3.24.9/lib/libgtkmm-3.0.so.1
#19 0x00007ffff6a9de5b in _gtk_marshal_BOOLEAN__BOXED () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#20 0x00007ffff7eda668 in g_closure_invoke () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#21 0x00007ffff7eeebcc in signal_emit_unlocked_R.isra.0 () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#22 0x00007ffff7eefda1 in signal_emit_valist_unlocked () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#23 0x00007ffff7ef62c2 in g_signal_emit_valist () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#24 0x00007ffff7ef636f in g_signal_emit () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#25 0x00007ffff6d524d4 in gtk_widget_event_internal.part () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#26 0x00007ffff6b7f8fc in gtk_entry_completion_popup_key_event () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#27 0x00007ffff6a9de5b in _gtk_marshal_BOOLEAN__BOXED () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#28 0x00007ffff7eda668 in g_closure_invoke () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#29 0x00007ffff7eeebcc in signal_emit_unlocked_R.isra.0 () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#30 0x00007ffff7eefda1 in signal_emit_valist_unlocked () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#31 0x00007ffff7ef62c2 in g_signal_emit_valist () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#32 0x00007ffff7ef636f in g_signal_emit () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgobject-2.0.so.0
#33 0x00007ffff6d524d4 in gtk_widget_event_internal.part () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#34 0x00007ffff6c05e8f in propagate_event () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#35 0x00007ffff6c078ae in gtk_main_do_event () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgtk-3.so.0
#36 0x00007ffff5ea4745 in _gdk_event_emit () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgdk-3.so.0
#37 0x00007ffff5efdf82 in gdk_event_source_dispatch () from /nix/store/54hz1pc0zk1cgm5qy7ky45963aq6j6mx-gtk+3-3.24.43/lib/libgdk-3.so.0
#38 0x00007ffff7dd1f54 in g_main_dispatch () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libglib-2.0.so.0
#39 0x00007ffff7dd4fd7 in g_main_context_iterate_unlocked.isra () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libglib-2.0.so.0
#40 0x00007ffff7dd55cc in g_main_context_iteration () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libglib-2.0.so.0
#41 0x00007ffff74f9d3d in g_application_run () from /nix/store/sr6skahp2mvi6y8d4g89a9vwk4yh4z0p-glib-2.80.2/lib/libgio-2.0.so.0
#42 0x000000000049ba4a in main ()
GST debug output
% env "GST_DEBUG=*:4" .../ahoviewer
0:00:00.000103900 3921998     0x25977280 INFO                GST_INIT gst.c:574:init_pre: Initializing GStreamer Core Library version 1.24.3
0:00:00.000129359 3921998     0x25977280 INFO                GST_INIT gst.c:575:init_pre: Using library installed in /nix/store/vcs2n7d80s8qqk8zbq6dhzcp5cfsmpqq-gstreamer-1.24.3/lib
0:00:00.000138901 3921998     0x25977280 INFO                GST_INIT gst.c:593:init_pre: Linux gnutoo 6.6.50 #1-NixOS SMP PREEMPT_DYNAMIC Sun Sep  8 05:54:49 UTC 2024 x86_64
0:00:00.000314760 3921998     0x25977280 INFO                GST_INIT gstmessage.c:129:_priv_gst_message_initialize: init messages
0:00:00.000711306 3921998     0x25977280 INFO                GST_INIT gstcontext.c:86:_priv_gst_context_initialize: init contexts
0:00:00.000932131 3921998     0x25977280 INFO      GST_PLUGIN_LOADING gstplugin.c:328:_priv_gst_plugin_initialize: registering 0 static plugins
0:00:00.001006246 3921998     0x25977280 INFO      GST_PLUGIN_LOADING gstplugin.c:236:gst_plugin_register_static: registered static plugin "staticelements"
0:00:00.001015836 3921998     0x25977280 INFO      GST_PLUGIN_LOADING gstplugin.c:238:gst_plugin_register_static: added static plugin "staticelements", result: 1
0:00:00.001041745 3921998     0x25977280 INFO            GST_REGISTRY gstregistry.c:1918:ensure_current_registry: reading registry cache: /home/benaryorg/.cache/gstreamer-1.0/registry.x86_64.bin
0:00:00.008741830 3921998     0x25977280 INFO            GST_REGISTRY gstregistrybinary.c:683:priv_gst_registry_binary_read_cache: loaded /home/benaryorg/.cache/gstreamer-1.0/registry.x86_64.bin in 0.007680 seconds
0:00:00.008837111 3921998     0x25977280 INFO            GST_REGISTRY gstregistry.c:1785:scan_and_update_registry: Validating plugins from registry cache: /home/benaryorg/.cache/gstreamer-1.0/registry.x86_64.bin
0:00:00.011267767 3921998     0x25977280 INFO            GST_REGISTRY gstregistry.c:1877:scan_and_update_registry: Registry cache has not changed
0:00:00.011278869 3921998     0x25977280 INFO            GST_REGISTRY gstregistry.c:1953:ensure_current_registry: registry reading and updating done
0:00:00.011313101 3921998     0x25977280 INFO                GST_INIT gst.c:807:init_post: GLib runtime version: 2.80.2
0:00:00.011320630 3921998     0x25977280 INFO                GST_INIT gst.c:809:init_post: GLib headers version: 2.80.2
0:00:00.011345662 3921998     0x25977280 INFO                GST_INIT gst.c:811:init_post: initialized GStreamer successfully
0:00:00.104902837 3921998     0x25977280 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:765:gst_element_factory_make_valist: no such element factory "gtkglsink"!
0:00:00.104924078 3921998     0x25977280 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:765:gst_element_factory_make_valist: no such element factory "gtksink"!
Failed to load gtkglsink or gtksink gstreamer plugin.
zsh: segmentation fault (core dumped)

I thought I had nailed it down to when starting ahoviewer with different versions in succession but apparently the crash is just kinda shy and doesn't like me trying to reproduce it so I was chasing a red herring for a while.
Turns out this is pretty much random as far as I can tell and does not require anything other than running ahoviewer repeatedly.

@ahodesuka
Copy link
Owner

ahodesuka commented Oct 11, 2024

Do you happen to see a message saying Failed to load gtkglsink or gtksink gstreamer plugin. when you start up ahoviewer?
The stacktrace leads me to believe it's crashing because m_Playbin is null inside videobox.cc in the reset_gstreamer_pipeline, which should only occur if you are missing the gtk gstreamer sinks.

This new runtime requirement only just got introduced after I merged a bunch of changes a few days ago.

@benaryorg
Copy link
Author

Do you happen to see a message saying Failed to load gtkglsink or gtksink gstreamer plugin. when you start up ahoviewer? The stacktrace leads me to believe it's crashing because m_Playbin is null inside videobox.cc in the reset_gstreamer_pipeline, which should only occur if you are missing the gtk gstreamer sinks.

This new runtime requirement only just got introduced after I merged a bunch of changes a few days ago.

I do indeed get that error message, I didn't think to include it since I got the message both with and without the crash.
I've been trying to reproduce it with GTK_DEBUG=all set to have a full log to include, but somehow I failed to reproduce it for the last like ten attempts.
Sounds like you have a vague idea of what the issue is though.?
I'll be happy to test any patches.

@ahodesuka
Copy link
Owner

It seems like NixOS doesn't provide the gtk sinks by default when building gst-plugins-good.
A quick search I found this solution https://discourse.nixos.org/t/how-to-provide-gstreamer-to-a-python-gtk-application/16814/7
Installing this should prevent the crash for you, but I'll commit a fix to prevent anyone from just crashing if this gstreamer plugin isn't installed.

@benaryorg
Copy link
Author

The stacktrace leads me to believe it's crashing because m_Playbin is null inside videobox.cc in the reset_gstreamer_pipeline, which should only occur if you are missing the gtk gstreamer sinks.

Not sure if relevant, but at least it's not null (although it's still in the first page of memory *shrug*):

(gdb) p m_Playbin
$1 = (GstElement *) 0xbec

It seems like NixOS doesn't provide the gtk sinks by default when building gst-plugins-good. A quick search I found this solution https://discourse.nixos.org/t/how-to-provide-gstreamer-to-a-python-gtk-application/16814/7 Installing this should prevent the crash for you

Thank you a whole lot, considering I'm already packaging the newer version of ahoviewer myself (if I ever have to see gtk2 again I'll scream) I can just add that without any problems.
The warning is gone for now, I'll try to reproduce a few more times but given how flakey this is I'd be lucky to hit it if it's still there.

but I'll commit a fix to prevent anyone from just crashing if this gstreamer plugin isn't installed.

Much appreciated!
I just wonder why it works sometimes but not other times.

I've got ahoviewer compiled with debug symbols and source code integration now so if there's anything you wanna know about the state when it crashes, I can provide that information.

@benaryorg
Copy link
Author

Okay, I have the fix (i.e. gst-plugins-good with gtkSupport = true;) applied, the warning is gone, yet I still encounter the crash.
Looking at frame 1 (AhoViewer::VideoBox::reset_gstreamer_pipeline) I can see that m_Playbin is set to something that's not null: 0xc42300, and the address roughly matches what heap allocations (malloc) returns, so it kind of seems like there's more to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants