RE: [gtkmm] bug with appending pages in a notebook



Hi,

It is not to you to allocate memory for sprintf function ?
have you try to do
char label[200]; // or anything else ... // personaly, I prefer
ostringstream
sprintf(label, "cust %i ...);
...
If you write to label (unalocated memory/somewhere memory), the stack is
perhaps corrupted and exiting your function give you an error.

But Your problem is perhaps another.

I Hope this can help you,
  Christophe.


-----Message d'origine-----
De : gtkmm-list-bounces gnome org
[mailto:gtkmm-list-bounces gnome org]De la part de cedric
Envoyé : mardi 25 mai 2004 12:11
À : gtkmm-list gnome org
Objet : [gtkmm] bug with appending pages in a notebook



Hello!
it has been a while since i ask for help, here i m back ;-)
i ve tried to solve it alone but it didn t success in it :'(

i think it s a really weird bug, but here it is:

i ve made an interface with a menubar, a toolbar and a functionnalities'
tree (=functree). in this 3 elements of my interface, we can select an
action, for example "add a customer": no matter if we call it from the
toolbar, from the menubar or from the functree, it always calls the same
method of my "test" plugin (so it calls test::add_customer() ). nothing
uncommon here i think...

the add_customer method adds a page in a notebook, and sets this page as
the current active page (of course we can select another page after
normally). but i have a WEIRD seg fault that i ll explain just after
showing the code:


-------------------------------------------------------------------------
void test::add_customer()
{
    CustomersFormat *c = new CustomersFormat();
    char *label ;
    sprintf(label, "cust %i", CustomersFormat::nb_cust_form);
    Formularies::mainViewNotebook_ptr->append_page(*c, label);

    int pn = Formularies::mainViewNotebook_ptr->page_num(*c);   // weird
here ///
    //std::cout << pn << std::endl;//pn is correctly set!!!
    Formularies::mainViewNotebook_ptr->set_current_page(pn);

    std::cout << "end add customer" << std::endl;
}
-------------------------------------------------------------------------

CustomersFormat is a class implementing a formulary that will be
displayed in the notebook.
mainViewNotebook_ptr is a global ptr on the notebook of my interface.

in the api i ve seen that page_num takes a "const Widget&" parameter,
but it doesn t change anything to my problem...
anyway, pn is correctly set, so...

here is the weird thing:
if we call this "add_customer" method from the menubar or from the
toolbar, it works.
but if we call it from the functree, it provoques a seg fault AFTER
having displayed the last std::cout "end add customer". this seg fault
seems to be due to the "page_num" method!
so if i remove the "page_num" line and replace pn by 0 (zero) in the
"set_current_page", it works if we call "add_customer" from the functree
BUT it provoques a seg fault if we call it from the menubar or from the
toolbar!!! and it displays normally "end add customer"...
i don t understand because NOTHING is done AFTER the last std::cout, and
especially because it should work either for none or for all! i don t
understand this difference between the menubar-toolbar // functree...
i m sure the links from menubar/toolbar/functree to the add_customer
method are ok since there are others method linked and they work fine!
and add_customer is called and executed entirely since it displays the
final std::cout!

thanks to the genius that will help me! :-)
regards,
cedric









_______________________________________________
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]