If FLTK makes a copy on assignement how it manages to update references to the old entry ?

I made a simple program with fluid to show the problem, to start with it crashs when a menu is selected !

What's wrong on it ?



En 08/11/2010 10:36:29, Greg Ercolano <[email protected]> escribió:

        I always try to use Fl_Menu::add() myself.. avoids weirdness.

Domingo Alvarez Duarte wrote:
Looking at the menu_generated code a bit more it seems that use of any
static structure isn't a good solution at all because it prevents derived classes to work properly, because if we derive a window with a menubar and
make some changes on it's menus like changing callbacks or renaming
entries this changes will reflect on the base class too and probably we
don't want that.

        No, IIRC, when a static array is assigned, the first time you
        make any changes, FLTK internally makes a malloc()ed copy so that
        it can then be safely modified.

        I believe FLTK keeps track of this internally, so once the allocated
        copy is made, it doesn't make new copies, and gets deleted when the
        menu does, or when a new static array is assigned.

        This behavior is documented in Fl_Menu::menu(const Fl_Menu_Item*),
        the method that assigns static arrays:

http://fltk.org/doc-1.3/classFl__Menu__.html#a0708c71ee8422bf3e92b8fa471eda9f
------------------------------------------------------------------------------
void Fl_Menu_::menu(const Fl_Menu_Item*m)
[..] If you try to modify the array (with add(), replace(), or remove())
a private copy is automatically done.
------------------------------------------------------------------------------

        I believe FLTK internally uses malloc() [or similar] to make
        a copy of the array's data, and sets a flag so it knows it's
dynamic, so that new copies don't need to be made, it gets free()ed, etc.

        Regarding fluid, maybe it could have an option to generate dynamic code
        with 'add()' as an option to generating a static array.


--
Usando el revolucionario cliente de correo de Opera: http://www.opera.com/mail/

Attachment: menubartest.fl
Description: Binary data

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to