On 9/9/26 03:17, Andre Steenveld wrote:
Found out what the problem was, use of static instances.
[..]problem solved.
Is it a bug report then for Georg Potthast?
He might still be maintaining the tutorial.
On Wednesday, 9 September 2026 at 16:44:26 UTC+1 Erco wrote:
Is it a bug report then for Georg Potthast?
He might still be maintaining the tutorial.
I wonder if it might imply a "weakness" in our docs though?Should we be explicitly saying that it may not be a "Good Idea" to add static objects as children of a dynamically created window?(Maybe we already do and I have forgotten, but I guess even in that case the point stands!)
I assume the "issue" here is that the stack-automatically created window goes out of scope when main() terminates, and is then reaped (deleted) and tries to clean up it's children - but in this case the children are static objects so don't want to be deleted at this point...
On 9/10/26 10:39 AM, Ian MacArthur wrote:
Sounds to me like the thing to do. (I have not seen any remark to using static instances in the documentation.)On Wednesday, 9 September 2026 at 16:44:26 UTC+1 Erco wrote:
Is it a bug report then for Georg Potthast?
He might still be maintaining the tutorial.
I wonder if it might imply a "weakness" in our docs though?Should we be explicitly saying that it may not be a "Good Idea" to add static objects as children of a dynamically created window?(Maybe we already do and I have forgotten, but I guess even in that case the point stands!)
This allows a whole tree to be deleted at once, without having to keep a pointer to all the children in the user code.
It is allowed that the Fl_Group and all of its children are automatic (local) variables, but you must declare the Fl_Group first, so that it is destroyed last.
If you add static or automatic (local) variables to an Fl_Group, then it is your responsibility to remove (or delete) all such static or automatic child widgets before destroying the group - otherwise the group will attempt to call delete operator on them leading to undefined behavior! "
https://www.fltk.org/doc-1.4/classFl__Group.html#a9a71aac1ca586825ff0c790f8f99f9cf
The fault of the posted demo program was that it `add()`ed static (global) child widgets to the group w/o removing them before the group was destroyed.
And I have noticed several examples in the tutorial by Georg Potthast where exactly this is how this is done.I assume the "issue" here is that the stack-automatically created window goes out of scope when main() terminates, and is then reaped (deleted) and tries to clean up it's children - but in this case the children are static objects so don't want to be deleted at this point...
In several variations like the one documented in the previous message.
But also variations where there is a static `Fl_Window win' instance and where parts are added which are local to a function context (and on the stack). When leaving the function then all instances that are in its local scope disapear and `win' will have dead pointer.
There is more than one way to violate this principle. The underlaying problem, IMHO, is the use of raw (and naked) pointers, `new' and `delete'.
Bad thing (for the Tutorial) is that most of the effects happens when the example is closing down and you will not notice it.
But when applying the same techniques in a library then it becomes a different thing in total. (Example works, why is my code throwing a null reference exception?)