Pedro Henrique Linhares wrote:
> This is what I get from my debugger :
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x080498d3 in MainWindow::translate (this=0x0) at Poligono.cpp:75
> 75 mygl->translate(1.0,1.0,0.0);
> (gdb) backtrace
> #0 0x080498d3 in MainWindow::translate (this=0x0) at Poligono.cpp:75
^^^^^^^^
The 'this=0x0' should be telling you a lot.
It means that in this line:
((MainWindow*)(w->parent()))->translate();
..w->parent() is returning a NULL. So when translate()
is being called, it's being called with a NULL context,
and will definitely crash.
I don't think 'w' is pointing to what you want; IIRC
w will point to the Fl_Menu_Item which in this context
has no parent.
I would suggest instead of doing this:
---- snip
Fl_Menu_Item MainWindow::menuitems[] = {
{ "&Iniciar", 0, 0, 0, FL_SUBMENU },
{ "&Translacao", FL_ALT + 'n', (Fl_Callback*)translate_cb},
{ "&Escala", FL_ALT + 'e', 0 },
{ "&Rotacao", FL_ALT + 'r', 0 },
{ "&Sair", FL_ALT + 'q', (Fl_Callback*)quit_cb},
{ 0 },
{"&Sobre",0,0,0,0},
{0},
{ 0 }
};
[..]
Menu = new Fl_Menu_Bar(0,0,w,25,"Menu");
[..]
Menu->menu(menuitems);
[..]
void MainWindow::translate_cb(Fl_Widget *w, void *v){
((MainWindow*)(w->parent()))->translate();
}
---- snip
..do it this way instead:
---- snip
[..]
Menu = new Fl_Menu_Bar(0,0,w,25,"Menu");
[..]
Menu->add("&Iniciar/&Translacao", FL_ALT + 'n', (Fl_Callback*)translate_cb,
(void*)Window); // NOTE: make Window the userdata
Menu->add("&Iniciar/&Escala", FL_ALT + 'e');
Menu->add("&Iniciar/&Rotacao", FL_ALT + 'r');
Menu->add("&Iniciar/&Sair", FL_ALT + 'q', (Fl_Callback*)quit_cb,
(void*)Window); // NOTE: make Window the userdata
Menu->add("&Sobre");
[..]
void MainWindow::translate_cb(Fl_Widget *, void *v) { // CHANGE THIS:
'w' removed
((MainWindow*)(v))->translate(); // CHANGE THIS:
'v' is now used (because it's set above to Window)
}
---- snip
..and remove the 'static Fl_Menu_Item menuitems[]' in the MainWindow
class.
This ensures 'v' in your translate_cb() function will be a pointer
to the MainWindow class instance you want, and you can ignore 'w'.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk