The current solution is not the best solution, and it should not break existing code. The background is the use of FLUID and other tools in the command line. Depending on the OS, opening a connection to the display may throw an error if the tool is intended for the command line. So we try to leave all measuring of fonts and other machine relevant data until the app calls `show()`. This works generally very well, because font size commonly don't need to be known until a widget is shown or drawn. But as we see here, this is not always the case and can not always be expected from the user.
I hope we find a solution to that soon. Probably just calling fl_open_display() whenever the graphics driver is requested, but not yet initialised, ie enough. Other core devs?
I think the OP's problem (which he's since corrected) is
probably one of assuming
a font had already been set, as I *think* what he's saying is
he called the getter
version of fl_font(), e.g. "fl_font(void)", without
having first called fl_font(face,size) to set it,
which probably would have yielded "undefined behavior".
Anyway, he's since fixed the problem.
It's certainly a valid use (and documented) to call fl_font()
outside of draw(),
such as to measure text with fl_measure() during widget
construction, before graphics
has been initialized. I'm guessing fl_font(face,size) checks
if graphics has not yet been
initialized, and initializes it.. but fl_font(void) does not
(and perhaps shouldn't)
On 1/21/23 10:01, Greg Ercolano wrote:
On 1/21/23 08:37, 'Matthias Melcher' via fltk.general wrote:
The current solution is not the best solution, and it should not break existing code. The background is the use of FLUID and other tools in the command line. Depending on the OS, opening a connection to the display may throw an error if the tool is intended for the command line. So we try to leave all measuring of fonts and other machine relevant data until the app calls `show()`. This works generally very well, because font size commonly don't need to be known until a widget is shown or drawn. But as we see here, this is not always the case and can not always be expected from the user.
I think too, IIRC, the font system initialization overhead is significant enough on some
platforms that it should be delayed until absolutely necessary. Esp. so that in FLTK applications
that don't even draw any text (pure graphics, like a speedometer on embedded hardware)
the overhead can be avoided.
I think the OP's problem (which he's since corrected) is
probably one of assuming
a font had already been set, as I *think* what he's saying is
he called the getter
version of fl_font(), e.g. "fl_font(void)", without
having first called fl_font(face,size) to set it,
which probably would have yielded "undefined behavior".
It's certainly a valid use (and documented) to call fl_font()
outside of draw(),
such as to measure text with fl_measure() during widget
construction, before graphics
has been initialized. I'm guessing fl_font(face,size) checks
if graphics has not yet been
initialized, and initializes it.. but fl_font(void) does not
(and perhaps shouldn't)
On Saturday, January 21, 2023 at 12:01:05 PM UTC-6 er...@seriss.com wrote:
I think the OP's problem (which he's since corrected) is probably one of assuming
a font had already been set, as I *think* what he's saying is he called the getter
version of fl_font(), e.g. "fl_font(void)", without having first called fl_font(face,size) to set it,
which probably would have yielded "undefined behavior".
Yes that is my case.
It's certainly a valid use (and documented) to call fl_font() outside of draw(),
such as to measure text with fl_measure() during widget construction, before graphics
has been initialized. I'm guessing fl_font(face,size) checks if graphics has not yet been
initialized, and initializes it.. but fl_font(void) does not (and perhaps shouldn't)
Yes exactly. My code was calling fl_font(void) without ever calling fl_font(face,size) at all, assuming that the font (and size) were initialized to some reliable "default" within FLTK (i.e., in the Fl_Window class constructor). Again, this happened when my text-oriented class was instantiated as a member of my class derived from Fl_Window. That text-oriented class calls fl_font() to set up sizes of things - again, assuming a default font + size is good.
From now on, to be rigorous, I will no longer assume there is such a thing as "default" font + size in FLTK, and that I must initialize it.
However, at least in my case, if the Fl_Window class constructor had indeed initialized all of this to some kind of defaults (including opening the display?), my code would have continued to sail smoothly on. But I understand that if opening the display fails in the constructor, about the only option is to throw an exception for the sake of the programmer who can catch it if desired.
On the other hand, maybe some other toolkits (Qt?) take care of this kind of initialization issue in a global initialization routine that programmers are required to call at the start? Like as with Fl::lock() in FLTK when we need to use MT and locks. Or, as it now appears, fl_open_display(), which might essentially fill that role now in FLTK, so calling it at the start of their program is what everyone should do as boilerplate.
On 1/21/23 22:33, Paul Hahn wrote:
On a completely different note... For some some reason when I respond with "inline" comments to someone's message I do not always get the expected indentation or vertical bars on the LHS. No need to chastise me about my "style"; I am trying to figure out what I am doing wrong.
Are you using the google web interface to the group?
If so that's probably the cause; the google web interface is
just not very good
at things like quoting properly.
Best thing to do if you can is redirect the fltk group to your
email,
set up a mail filter to move all fltk messages to a folder
separate from your mailbox,
and use that to read and reply.
I think most of us use the email interface read and reply.
That seems to handle
everything better.