Re: Crashes using custom signals



Sorry, I forgot your main problem.

It seems that the error comes from the initialization of the _signal_a member. Try to change the order of the main_window, signal_a variable to this:

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

So the _signal_a should be _before_ the _main_window.

----- Original Message -----
From: "Phillip Neiswanger" <sigsegv0 gmail com>
To: dexter <dexter balabit hu>
Sent: Thu, Jan 15, 2009 10:53:34 AM +0100
Subject: Crashes using custom signals

Thanks.

That solves the gtk warnings, but does not solve the core dump when trying to connect() in the MainWindow constructor.
--
phil


On Thu, 15 Jan 2009 02:06:22 -0700, dexter <dexter balabit hu> wrote:

Hi,

I'm not sure, but I think you're missing the Gtk::Main initialization before creating the mainwindow. So this:
 > Application::Application()
 >     : _main_window(new MainWindow)
 > {

should be something like this:
 > Application::Application(int &argc, char **&argv)
 >     : Gtk::Main(argc, argv), _main_window(new MainWindow)
 > {


----- Original Message -----
From: "Phillip Neiswanger" <sigsegv0 gmail com>
To: gtkmm-list gnome org
Sent: Thu, Jan 15, 2009 3:02:13 AM +0100
Subject: 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;
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list






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