FL_Tree sample code crashes

22 views
Skip to first unread message

Robin Rowe

unread,
Mar 28, 2018, 9:13:14 PM3/28/18
to fltkg...@googlegroups.com
FL_tree sample code crashes as soon as I click on "Flintstones"...

http://seriss.com/people/erco/fltk/Fl_Tree/Fl_Tree/test-simple.cxx

Seems to be a recursive stack overflow on TreeCallback().

The console outputs...

TreeCallback: data=1234, item='Flintstones'

...over and over, then crashes. Windows 10 VS2017.

What's the fix?

Thanks,

Robin

Greg Ercolano

unread,
Mar 29, 2018, 4:08:15 PM3/29/18
to fltkg...@googlegroups.com
On 03/28/18 18:13, Robin Rowe wrote:
> http://seriss.com/people/erco/fltk/Fl_Tree/Fl_Tree/test-simple.cxx

See the red text on the main page for that code:
http://seriss.com/people/erco/fltk/Fl_Tree/

Note that Fl_Tree now comes with FLTK, and is no longer a separate project.

In short, use the examples that come with FLTK (in test/ and examples/)
and not the code at the above page; that code is no longer maintained,
as it is frozen in place as a historic artifact of the code at the time
it was first integrated into FLTK in 2009.

If you're somehow using a really old version of fltk (earlier than 1.3.0)
that didn't come with Fl_Tree, and are trying to integrate that old Fl_Tree
version, let me know by private mail, and we can probably figure out a way
to backport one of the more recent versions of Fl_Tree (from 1.4.x) to it.

Greg Ercolano

unread,
Mar 29, 2018, 4:59:29 PM3/29/18
to fltkg...@googlegroups.com
On 03/29/18 13:08, Greg Ercolano wrote:
> On 03/28/18 18:13, Robin Rowe wrote:
>> http://seriss.com/people/erco/fltk/Fl_Tree/Fl_Tree/test-simple.cxx
>
> See the red text on the main page for that code:
> http://seriss.com/people/erco/fltk/Fl_Tree/
>
> Note that Fl_Tree now comes with FLTK, and is no longer a separate project.
>
> In short, use the examples that come with FLTK (in test/ and examples/)
> and not the code at the above page; that code is no longer maintained,
> as it is frozen in place as a historic artifact of the code at the time
> it was first integrated into FLTK in 2009.


Oh, and the specific fix would be to use the examples/tree-simple.cxx
code example that comes in fltk's source directory.

The old code example won't work with the newer Fl_Tree because
that example had to emulate selection behavior that is now default,
making the callback code redundant. (Many features were added since the
2009 code, including shift- and toggle-selection)

Doing so also retriggers the callback, something the old code didn't
do, and didn't have the 'docallback' option flag (which is default 'on').

So to 'fix' the old code example, you'd change these two lines:

tree->deselect_all(); // deselect all items
tree->select(item); // select this one

..so that the new 'docallback' flag is disabled.

So either replace the above with:

tree->deselect_all(NULL, 0); // deselect all: start at root, don't redo callback
tree->select(item, 0); // select this item, don't redo callback

..or just:

tree->select_only(item, 0); // select only: this item, don't redo callback

Note that this just re-implements the already default behavior, so this
would be redundant. But if you wanted to implement your own selection behavior,
that's how to do it without causing reentry.
Reply all
Reply to author
Forward
0 new messages