Crashes using custom signals



Hi,

At this end of this message is a simple test program. Note the connect() call in the Application constructor. If I move the connect() out of that constructor and into the MainWindow constructor like so:

MainWindow::MainWindow()
{
    Application::instance()->
        signal_a().
           connect(sigc::mem_fun(*this, &MainWindow::on_a));
}

I get a core dump in the connect() call. The back trace looks like this:

(gdb) bt
#0 0x48cfb89f in std::_List_node_base::hook () from /usr/lib/libstdc++.so.5 #1 0x48808501 in std::list<sigc::slot_base, std::allocator<sigc::slot_base> >::insert () from /usr/X11R6/lib/libglibmm-2.4.so.1
#2  0x488292ff in sigc::internal::signal_impl::insert ()
   from /usr/X11R6/lib/libsigc-2.0.so.0
#3  0x48829343 in sigc::internal::signal_impl::connect ()
   from /usr/X11R6/lib/libsigc-2.0.so.0
#4  0x48829526 in sigc::signal_base::connect ()
   from /usr/X11R6/lib/libsigc-2.0.so.0
#5  0x0804ce7c in sigc::signal0<void, sigc::nil>::connect (this=0xbfbfe7c0,
    slot_= 0xbfbfe7e0) at signal.h:2655
#6  0x0804c3fe in MainWindow (this=0x8092180) at t.cc:39
#7  0x0804c96c in Application (this=0xbfbfe860) at t.cc:54
#8  0x0804cc91 in main () at t.cc:82

Why? What's wrong with my code?

Here's the code:

#include <gtkmm/main.h>
#include <gtkmm/window.h>

#include <memory>
#include <iostream>

typedef sigc::signal<void> SignalTypeA;

class MainWindow;

class Application : public Gtk::Main
{
  public:
	Application();
   ~Application();

	SignalTypeA signal_a();

	static Application* instance();

	void run();

  private:
	std::auto_ptr<MainWindow> _main_window;
	SignalTypeA _signal_a;
};

class MainWindow : public Gtk::Window
{
  public:
	MainWindow();
   ~MainWindow();

	void on_a();
};

MainWindow::MainWindow()
{
}

MainWindow::~MainWindow()
{
}

void
MainWindow::on_a()
{
std::cout << "Test output" << std::endl;
}

Application::Application()
	: _main_window(new MainWindow)
{
	signal_a().connect(sigc::mem_fun(*_main_window, &MainWindow::on_a));
}

Application::~Application()
{
}

SignalTypeA
Application::signal_a()
{
	return _signal_a;
}

Application*
Application::instance()
{
	return dynamic_cast<Application*>(Gtk::Main::instance());
}

void
Application::run()
{
	Gtk::Main::run(*_main_window);
}

int
main()
{
	Application app;

	app.run();

	return 0;
}


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