Greetings all,
When I do Fl_Menu_Item popup() call from right-clicking one of the items added to the list, I get a crash. Here's the minimal code:
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Hold_Browser.H>
#include <FL/Fl_Menu_Item.H>
#define SV_FLTK_FONT_31 31
Fl_Double_Window * mainWin = NULL;
Fl_Hold_Browser * hostList = NULL;
int nMenuFontSize = 11;
/*
handle mouse click and other events from the host list
(no parameters used so all parameter names removed)
*/
void svHandleHostListEvents (Fl_Widget *, void *)
{
// right-click
if (Fl::event_button() == FL_RIGHT_MOUSE)
{
// create context menu
// text,shortcut,callback,user_data,flags,labeltype,labelfont,labelsize
const Fl_Menu_Item miMain[] = {
{"Connect", 0, 0, 0, 0, 0, SV_FLTK_FONT_31, nMenuFontSize},
{"Edit", 0, 0, 0, 0, 0, SV_FLTK_FONT_31, nMenuFontSize},
{"Delete...", 0, 0, 0, 0, 0, SV_FLTK_FONT_31, nMenuFontSize},
{0}
};
// show context menu and return selected item, if any
const Fl_Menu_Item * miRes = miMain->popup(Fl::event_x() + 14, Fl::event_y() - 10);
if (miRes != NULL)
{
const char * strRes = miRes->text;
printf("%s\n", strRes);
}
}
}
/* main program */
int main (int argc, char **argv)
{
// tells FLTK we're a multithreaded app
Fl::lock();
// set graphics / display options
Fl::visual(FL_DOUBLE | FL_RGB);
// create main window
mainWin = new Fl_Double_Window(1024, 768);
mainWin->size_range(800, 600, 32767, 32767);
mainWin->label("Minimal FLTK Example");
mainWin->xclass("minimalfltk");
// create host list
hostList = new Fl_Hold_Browser(0, 0, 200, 550);
hostList->clear_visible_focus();
hostList->callback(svHandleHostListEvents, NULL);
hostList->box(FL_THIN_DOWN_BOX);
hostList->add("Test item1", NULL);
hostList->add("Test item2", NULL);
mainWin->end();
mainWin->show(argc, argv);
return Fl::run();
}
Here is the gdb backtrace after I right-click one of the added items:
Program received signal SIGSEGV, Segmentation fault.
__strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:120
120 ../sysdeps/x86_64/multiarch/../strlen.S: No such file or directory.
(gdb) bt
#0 __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:120
#1 0x000055555559d6f8 in fontopen (name=0x0, size=11, core=false, angle=0) at fl_font_xft.cxx:147
#2 0x000055555559dc16 in Fl_Font_Descriptor::Fl_Font_Descriptor (this=0x555555620a60, name=0x0, fsize=11, fangle=0) at fl_font_xft.cxx:336
#3 0x000055555559d622 in fl_xft_font (driver=0x5555555f0eb0, fnum=31, size=11, angle=0) at fl_font_xft.cxx:125
#4 0x000055555559d6ad in Fl_Xlib_Graphics_Driver::font (this=0x5555555f0eb0, fnum=31, size=11) at fl_font_xft.cxx:139
#5 0x00005555555660e1 in fl_font (face=31, fsize=11) at ../FL/fl_draw.H:509
#6 0x00005555555a0bea in fl_normal_measure (o=0x7fffffffd330, W=@0x7fffffffd32c: 0, H=@0x7fffffffd39c: 21845) at fl_labeltype.cxx:42
#7 0x00005555555a0dc6 in Fl_Label::measure (this=0x7fffffffd330, W=@0x7fffffffd32c: 0, H=@0x7fffffffd39c: 21845) at fl_labeltype.cxx:93
#8 0x0000555555578808 in Fl_Menu_Item::measure (this=0x7fffffffd780, hp=0x7fffffffd39c, m=0x0) at Fl_Menu.cxx:165
#9 0x00005555555794e0 in menuwindow::menuwindow (this=0x7fffffffd550, m=0x7fffffffd780, X=487, Y=247, Wp=0, Hp=0, picked=0x0, t=0x0,
menubar=0, menubar_title=0, right_edge=1920) at Fl_Menu.cxx:346
#10 0x000055555557b379 in Fl_Menu_Item::pulldown (this=0x7fffffffd780, X=487, Y=247, W=0, H=0, initial_item=0x0, pbutton=0x0, t=0x0, menubar=0)
at Fl_Menu.cxx:858
#11 0x000055555557bde4 in Fl_Menu_Item::popup (this=0x7fffffffd780, X=39, Y=30, title=0x0, picked=0x0, button=0x0) at Fl_Menu.cxx:1028
#12 0x000055555556220f in svHandleHostListEvents () at minimal_fltk.cxx:35
#13 0x0000555555587d5d in Fl_Widget::do_callback (this=0x5555556217d0, o=0x5555556217d0, arg=0x0) at Fl_Widget.cxx:348
#14 0x0000555555562701 in Fl_Widget::do_callback (this=0x5555556217d0) at ../FL/Fl_Widget.H:861
#15 0x000055555556bbb3 in Fl_Browser_::handle (this=0x5555556217d0, event=2) at Fl_Browser_.cxx:927
#16 0x0000555555563e9b in send_event (event=2, to=0x5555556217d0, window=0x555555617680) at Fl.cxx:1220
#17 0x000055555556427c in Fl::handle_ (e=2, window=0x555555617680) at Fl.cxx:1417
#18 0x0000555555563f25 in Fl::handle (e=2, window=0x555555617680) at Fl.cxx:1300
#19 0x00005555555917d7 in fl_handle (thisevent=...) at Fl_x.cxx:2258
#20 0x000055555558bf46 in do_queued_events () at Fl_x.cxx:212
#21 0x000055555558ca9b in fd_callback () at Fl_x.cxx:469
#22 0x000055555558c4f5 in fl_wait (time_to_wait=1e+20) at Fl_x.cxx:278
#23 0x0000555555563137 in Fl::wait (time_to_wait=1e+20) at Fl.cxx:627
#24 0x000055555556316d in Fl::run () at Fl.cxx:642
#25 0x00005555555623b9 in main (argc=1, argv=0x7fffffffe228) at minimal_fltk.cxx:74
Even if I remove the , NULL at the spot where I'm adding items to the hold-browser, I still get the crash, so I don't think it's that.
Does anyone see anything obvious that I'm missing?
By the way, the source-code styling choices for Groups is pretty dismal. Have you guys thought of moving away from Groups to something more suitable for code listings and the like?
Thanks,
Will B
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/7a952096-5755-4d9c-8976-bd40c2bc5930n%40googlegroups.com.