Re: signal within a signal handler



On 9/8/05, Murray Cumming <murrayc murrayc com> wrote:
> On Tue, 2005-09-06 at 08:26 -0500, Jonathon Jongsma wrote:
> > I'm curious, is it legal to emit a signal within a handler for another
> > signal?
> 
> Yes, absolutely.
> 
> >  The reason I'm asking is that I'm trying to do such a thing
> > and I keep getting a segfault when the event occurs.
> 
> gdb or valgrind will give more information.
> 

Here's the backtrace from gdb.  item #2 is obviously my handler for a
button_release_event, which then emits my custom signal.  I'm afraid
that I can't figure a lot out from this backtrace -- do you see
anything obvious here? (code is shown below)

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 12572)]
0x40ccd37e in std::_List_node_base::swap () from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0x40ccd37e in std::_List_node_base::swap () from /usr/lib/libstdc++.so.6
#1  0x0807dabe in sigc::internal::signal_emit0<bool, sigc::nil>::emit (
    impl=0x817d748) at stl_list.h:901
#2  0x08078c4f in gcs::Widgets::ColorSwatch::on_button_release_event (
        this=0x19, e=0x8254d20) at signal.h:1608
#3  0x4021d6c2 in Gtk::Widget_Class::button_release_event_callback ()
           from /usr/lib/libgtkmm-2.4.so.1
#4  0x4078747e in _gtk_marshal_BOOLEAN__BOXED ()
              from /usr/lib/libgtk-x11-2.0.so.0
#5  0x40a71f18 in g_cclosure_new_swap () from /usr/lib/libgobject-2.0.so.0
#6  0x40a725bb in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#7  0x40a81c72 in g_signal_stop_emission () from /usr/lib/libgobject-2.0.so.0
#8  0x40a82c05 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#9  0x40a831fe in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#10 0x40876cf7 in gtk_widget_send_expose () from /usr/lib/libgtk-x11-2.0.so.0
#11 0x40785f92 in gtk_propagate_event () from /usr/lib/libgtk-x11-2.0.so.0
#12 0x40784de6 in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#13 0x409868e5 in _gdk_events_queue () from /usr/lib/libgdk-x11-2.0.so.0
#14 0x40c243f1 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#15 0x40c27647 in g_main_context_check () from /usr/lib/libglib-2.0.so.0
#16 0x40c27b98 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#17 0x40784693 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#18 0x401b3359 in Gtk::Main::run_impl () from /usr/lib/libgtkmm-2.4.so.1
#19 0x401b31a3 in Gtk::Main::run () from /usr/lib/libgtkmm-2.4.so.1
#20 0x0806de26 in main (argc=1, argv=0xbffff644) at main.cc:73


Here's my on_button_release_event code:
bool ColorSwatch::on_button_release_event(GdkEventButton *e)
{
    //if (e->type == GDK_BUTTON_RELEASE)
    {
        if (e->button == 1)
        {
            // User pressed left mouse button
            m_signal_selected.emit();
            debug("In on_button_press_event; emitted signal_selected()");
        }
    }
    return true;
}

m_signal_selected is defined as follows:
sigc::signal<bool> m_signal_selected;

I've registered a handler for m_signal_selected in the constructor of
the class as follows:
m_signal_selected.connect(sigc::mem_fun(*this, &ColorSwatch::on_test));

The handler on_test is defined as follows:
bool ColorSwatch::on_test()
{
    debug("on_test");
    return true;
}

When I register even a trivial handler for m_signal_selected (such as
on_test shown above), I get a segmentation fault (backtrace shown
above).  When I have no signal handler registered for
m_signal_selected, the signal emits but no segfault occurs.

I'd be grateful for any help anyone can provide.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]