Bug (or issue) in callbacks generated by fluid on macOS using system menu bar inside C++ Classes

22 views
Skip to first unread message

Roberto Panetta

unread,
May 18, 2024, 2:53:02 AMMay 18
to fltk.general
Bug (or issue) in callbacks generated by fluid on macOS using system menu bar inside C++ Classes


I found a possible bug in the resulting menu callbacks generated by Fluid on macOS using the System Menu Bar Fl_Sys_Menu_Bar and _only_ when inside a C++ Class.
The problem it is not present if the menu is placed inside the windows also on MacOS, using Fl_Menu_Bar and NOT Fl_Sys_Menu_Bar
The problem is not present if compiled on Linux or MS Windows (because there is no System Menu Bar)
The problems is not present even on Mac if the generation is made outside a C++ Class (as example inside the main as in the small example projects)


It seems the problem is when in the static callback Before calling the inline callback, on the code: 'o->parent()->user_data()'
It always fails
I created a simple project with Fluid to show the problem


As said above the code always fails at:
((FluidPPMacMenu*)(o->parent()->user_data()))->cb_item_i(o,v);
Failing to resolve 'o->parent()->user_data()' and causing a crash

So the problem seems being retrieving the user data from the menu item parent (ONLY WHEN) using a menu item on macOS and using the System Menu Bar and inside a C++ Class

I have this problem in more then one project
All works perfectly under Windows compiling with Visual Studio or in Linux or also on macOS if using the menubar inside a windows or outside a C++ class

Maybe I'm doing something wrong, ..not sure

Platform: macOS 14.5
Xcode 15.4
With all macOS SDK from 10.13 to 14.5



The following code is for "FluidPPMacMenu.h":

---------------------------------------------

#ifndef FluidPPMacMenu_h
#define FluidPPMacMenu_h
#include <FL/Fl.H>
#include <FL/Fl_Sys_Menu_Bar.H>
#include <FL/Fl_Menu.H>
#include <FL/Fl_Double_Window.H>

class FluidPPMacMenu {
public:
  void testOne();
  FluidPPMacMenu();
  static Fl_Menu_Item menu_MenuBar[];
private:
  inline void cb_item_i(Fl_Menu_*, void*);
  static void cb_item(Fl_Menu_*, void*);
};
#endif

---------------------------------------------




and for FluidPPMacMenu.cxx:
---------------------------------------------



// generated by Fast Light User Interface Designer (fluid) version 1.0400

#include "FluidPPMacMenu.h"
typedef struct FLMESSAGE{
    int msgType;
    void *data;
   
} FLMESSAGE;

void FluidPPMacMenu::cb_item_i(Fl_Menu_*, void*) {
  testOne();
}
void FluidPPMacMenu::cb_item(Fl_Menu_* o, void* v) {
  ((FluidPPMacMenu*)(o->parent()->user_data()))->cb_item_i(o,v);
}

Fl_Menu_Item FluidPPMacMenu::menu_MenuBar[] = {
 {"Menu One", 0,  0, 0, 64, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
 {"item One", 0,  (Fl_Callback*)FluidPPMacMenu::cb_item, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0},
 {0,0,0,0,0,0,0,0,0}
};

void FluidPPMacMenu::testOne() {
  printf("Hello World\n");
}

FluidPPMacMenu::FluidPPMacMenu() {
  Fl_Double_Window* w;
  { Fl_Double_Window* o = new Fl_Double_Window(480, 320);
    w = o; (void)w;
    o->user_data((void*)(this));
    { Fl_Sys_Menu_Bar* o = new Fl_Sys_Menu_Bar(0, 0, 480, 18, "MenuBar");
      o->box(FL_UP_BOX);
      o->color(FL_BACKGROUND_COLOR);
      o->selection_color(FL_SELECTION_COLOR);
      o->labeltype(FL_NORMAL_LABEL);
      o->labelfont(0);
      o->labelsize(14);
      o->labelcolor(FL_FOREGROUND_COLOR);
      o->align(Fl_Align(FL_ALIGN_CENTER));
      o->when(FL_WHEN_RELEASE_ALWAYS);
      o->menu(menu_MenuBar);
    } // Fl_Sys_Menu_Bar* o
    o->end();
  } // Fl_Double_Window* o
  w->show();
}

int main(int argc, char **argv) {
  new FluidPPMacMenu();


  return Fl::run();
}


---------------------------------------------


Included also the Fluid file to generate both files
FluidPPMacMenu.fl

Roberto Panetta

unread,
May 18, 2024, 2:53:14 AMMay 18
to fltk.general
FluidPPMacMenu.fl

Matthias Melcher

unread,
May 18, 2024, 8:07:26 AMMay 18
to fltk.general
I will try to take look at that in the next two days, time permitting. 

For general bug reports, it's usually better to use https://github.com/fltk/fltk/issues as it provides better ways to keep track of bugs and link to source code.

 - Matthias
Reply all
Reply to author
Forward
0 new messages