QB64.org Forum

Active Forums => Bugs => Topic started by: SMcNeill on November 15, 2018, 10:00:26 am

Title: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 10:00:26 am
Code: QB64: [Select]
  1. _FONT _LOADFONT("cour.ttf", 16, "monospace")
  2. ScaleScreen 0 'initialize the font settings
  3.  
  4. PRINT "Hello World"
  5.  
  6. ScaleScreen 50
  7. ScaleScreen 200
  8. ScaleScreen 150
  9.  
  10.  
  11.  
  12.  
  13.  
  14. SUB ScaleScreen (percent AS INTEGER)
  15.     STATIC FontSize(4 TO 100), RanOnce
  16.     IF NOT RanOnce THEN
  17.         RanOnce = -1
  18.         FOR i = 4 TO 100
  19.             _LIMIT 25
  20.             F = _LOADFONT("cour.ttf", i, "monospace")
  21.             FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
  22.             _FREEFONT F
  23.         NEXT
  24.     END IF
  25.     IF percent = 0 THEN EXIT SUB
  26.     h = _FONTWIDTH
  27.     desiredscale = (percent / 100) * h
  28.     FOR i = 5 TO 100
  29.         IF FontSize(i) > desiredscale THEN EXIT FOR
  30.     NEXT
  31.     Ftemp = _FONT
  32.     F = _LOADFONT("cour.ttf", i - 1, "monospace")
  33.     _FONT F
  34.     IF Ftemp <> 16 THEN _FREEFONT Ftemp
  35.  
  36.  

Try the code above, and it works fine.

Remove the _LIMIT inside the SUB and then run it.  It'll die instantly.

For whatever reason, there has to be a timed gap somewhere between _LOADFONT and _FREEFONT when running them in a loop like this, or else the program simply explodes.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: johnno56 on November 15, 2018, 02:48:40 pm
I ran the program on my Linux box 'as is' and ran just fine. Commented out the 'limit' command and it appeared not to run. Then executed via a 'terminal'. The IDE did not change in any way but the 'terminal' displayed 'Segmentation fault'. I hope this is helpful.

J
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: johnno56 on November 15, 2018, 02:58:12 pm
I was curios as to why the 'limit' was put there... Experimented a little and figured it was to 'slow' the process... Left the 'limit' commented out and inserted a '_DELAY 0.1' before the '_FREEFONT' and it worked just fine.

My theory is: The font is being loaded... QB64 does its thing... _FREEFONT is encountered, possibly before the 'load' has finished, and promptly dies because there is no font to 'free'.... Just a guess... Thoughts?
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: FellippeHeitor on November 15, 2018, 03:14:33 pm
No crash in Windows XP even with _LIMIT commented out. I assume you're on to a fix to it, Steve?
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 03:32:35 pm
No crash in Windows XP even with _LIMIT commented out. I assume you're on to a fix to it, Steve?

No idea WTH the problem is.  I can't see any reason why we'd set fault from this.  If anybody has any thoughts, I'd love to hear them.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 03:36:15 pm
I was curios as to why the 'limit' was put there... Experimented a little and figured it was to 'slow' the process... Left the 'limit' commented out and inserted a '_DELAY 0.1' before the '_FREEFONT' and it worked just fine.

My theory is: The font is being loaded... QB64 does its thing... _FREEFONT is encountered, possibly before the 'load' has finished, and promptly dies because there is no font to 'free'.... Just a guess... Thoughts?

My only thought there is, "Why would _FONTWIDTH work then for us, on the previous line?"  If there's no font to free, how can we get the width of that font?
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 03:41:10 pm
ScaleScreen? My older version does not support ScaleScreen. What is it?

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 04:28:34 pm
ScaleScreen? My older version does not support ScaleScreen. What is it?

Pete

It's a sub inside the example which will scale a text screen by X amount.  Scroll the code inside the code box next time.  :D
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 04:34:02 pm
Narrowed down the issue to being _LOADFONT related, but have no idea WHY it's screwing up. 

Separate the routine to 3 different loops and you can tell; _FONTHEIGHT and _FREEFONT work just fine in a loop.  The _LOADFONT, however, will seg fault and die in a loop, unless a delay is installed so it can do its thing without glitching out.

**********

On a completely unrelated note, I did find a memory leak in _LOADFONT and can easily fix it -- but it has absolutely no bearing on the current issue. 
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 04:42:24 pm
Ah, it looked like the code ended at the SLEEP statement. I was wondering why ScreenScale wasn't _ScreenScale if it was a new keyword. Anyway, I gave it a run and it worked fine until I removed the _LIMIT 25, and then it crashed without message. I'm running QB64 v 1.1 from September 2016 on a Windows 10. I actually have a more current version on my Win 7, but it is away at a resort for a well deserved rest.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 04:44:38 pm
Ah, it looked like the code ended at the SLEEP statement. I was wondering why ScreenScale wasn't _ScreenScale if it was a new keyword. Anyway, I gave it a run and it worked fine. I'm running QB64 v 1.1 from September 2016 on a Windows 10. I actually have a more current version on my Win 7, but it is away at a resort for a well deserved rest.

Pete

Did you comment out the _LIMIT and then try it?  Without that delay, that's when it dies.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 04:46:20 pm
I just edited my post. It does crash when _LIMIT 25 is remarked out.

PS: Sorry for the short attention span. I'm watching a bigger crash of NVIDIA stock. 14% down in after hours upon releasing earnings and over 25% down from its high. Lucky for me, I don't own shares. Fascinating times.

Pete 
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 04:52:35 pm
And, here's another odd bit of behavior which has me utterly baffled:

I can purge libq using the batch files inside the internal/c folder, compile, and the program runs perfectly fine --- ONCE.  I can click the exe to try and run it a second time, and it dies.  I can recompile it, and it dies.  Nothing works...

But, if I purge libqb and then recompile, it runs perfectly fine ONCE...

I'm utterly baffled to explain that behavior.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 04:57:49 pm
Interesting that if I change to _LIMIT 1, it doesn't crash, but the window just stays open and nothing prints to it. Key presses have no effect. If I change to _LIMIT 10, it completely crashes. _LIMIT 25 works.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 05:07:34 pm
Interesting that if I change to _LIMIT 1, it doesn't crash, but the window just stays open and nothing prints to it. Key presses have no effect. If I change to _LIMIT 10, it completely crashes. _LIMIT 25 works.

Pete

Limit slows the process.  Limit 1 traps you in the loop for 96 seconds.  (1 time per second, from I = 4 to 100)...  You just got to leave it open that long.

Limit 10 should work perfectly fine...  That's a longer delay than limit 25.   (10 times a second would take 9.6 seconds, vs 25 times a second for 4 seconds run time.)

As I say, the behavior has me lost ATM.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 05:17:30 pm
It's erratic alright. I tried a few more times with _LIMIT 1. On the second try it crashed in 1 second. The next try it did run after 96 seconds but  after two key presses, it crashed. I ran it again with _LIMIT 1 and got through to the end on the third try.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 05:40:14 pm
OK, I did about 30 tests with _LIMIT 10 and it failed 3 times. What I noticed when it failed, each time the mouse went from a pointer to that circular moving pointer for less than a second... and then it crashed. It does not seem to be window location, as I tried it adding _SCREENMOVE 0, 0 and it worked the first try, and then failed on the second try.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 05:47:36 pm
And you have to love the "works sometimes, crashes sometimes" glitches.  They make things sooooooooo much easier to debug. 
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 06:07:33 pm
So I changed _LIMIT 10 to _DELAY .05. On the seventh attempt, it failed. I retried it for 40 more times, and it worked.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Cobalt on November 15, 2018, 06:30:52 pm
program errors out on line 1 for me. apparently I don't have that font.
after substituting a different font I have come to a conclusion,

Thee error is timing based.

there must be something that's not getting done before something else tries to happen. its easier to see, i feel, with _DELAY cause you can play with it incrementing .0001 until it stops erroring out.the more delay you get the less often it errors out.
I'm guessing its in _LOADFONT, as I commented out the _FONTWIDTH line and it still crashed but commenting out the _LOADFONT line and it doesn't, for me, crash any more.  I believe we have seen this before, I think with _SCREENMOVE, where without a slight delay the screen wouldn't move(cause the window handle wasn't ready yet?). so maybe this as a similar root but causes a crash instead of just not doing what its supposed to.

Could it be accessing memory too fast?
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 06:44:59 pm
Just a note...

Code: QB64: [Select]
  1.     FOR i = 4 TO 100
  2.         _LIMIT 100
  3.         F = _LOADFONT("cour.ttf", i, "monospace")
  4.         _LIMIT 100
  5.         FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
  6.         _LIMIT 100
  7.         _FREEFONT F
  8.     NEXT
  9.  

I tried _LIMIT 100 in place of _LIMIT 25, and it failed after a few tries, as expected. I kept adding _LIMIT 100 between font statements to slow them down but they all failed. _DELAY .001 between all statements fails, too.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 07:32:29 pm
Oh, this is interesting...

I tried putting _DELAY .05 between each font statement and it worked 50 times. I then made an automatic RUN, with my intention to just let it run for an hour and see if it was still up or if it crashed at some point. Instead, I get an ERROR 9 subscript out of range at line 23.

Code: QB64: [Select]
  1. _FONT _LOADFONT("cour.ttf", 16, "monospace")
  2. ScaleScreen 0 'initialize the font settings
  3.  
  4. PRINT "Hello World"
  5.  
  6. ScaleScreen 50
  7. ScaleScreen 200
  8. ScaleScreen 150
  9.  
  10. SUB ScaleScreen (percent AS INTEGER)
  11. STATIC FontSize(4 TO 100), RanOnce
  12. IF NOT RanOnce THEN
  13.     RanOnce = -1
  14.     FOR i = 4 TO 100
  15.         _DELAY .05
  16.         F = _LOADFONT("cour.ttf", i, "monospace")
  17.         _DELAY .05
  18.         FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
  19.         _DELAY .05
  20.         _FREEFONT F
  21.     NEXT
  22. IF percent = 0 THEN EXIT SUB
  23. desiredscale = (percent / 100) * h
  24. FOR i = 5 TO 100
  25.     IF FontSize(i) > desiredscale THEN EXIT FOR
  26. Ftemp = _FONT
  27. F = _LOADFONT("cour.ttf", i - 1, "monospace")
  28. IF Ftemp <> 16 THEN _FREEFONT Ftemp
  29.  

I do agree with Cobalt this is likely a timing issue. Taking out _FREEFONT in the FOR/NEXT loop doesn't change anything, so it seems like somehow a font statement is taking too long to process and has not completed before the next statement is run.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 08:02:43 pm
As I mentioned on the previous page, it's a _LOADFONT issue.  All you need to see the issue is:

FOR I = 1 TO 100
    F = _LOADFONT("cour.ttf", i, "monospace")
NEXT

Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 08:25:30 pm
I'm still stuck on why the auto-run code I put in the last code box post won't work.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 08:51:40 pm
I'm still stuck on why the auto-run code I put in the last code box post won't work.

Because, from my experience, RUN is buggy.  It's probably glitching out somehow with the STATIC inside the SUB.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 09:18:59 pm
I can get your original program to run without _LIMIT 25 if I add a delay after line 2.

Code: QB64: [Select]
  1. _FONT _LOADFONT("cour.ttf", 16, "monospace")
  2. ScaleScreen 0 'initialize the font settings
  3.  
  4. PRINT "Hello World"
  5.  
  6. ScaleScreen 50
  7. ScaleScreen 200
  8. ScaleScreen 150
  9.  
  10. SUB ScaleScreen (percent AS INTEGER)
  11. STATIC FontSize(4 TO 100), RanOnce
  12. IF NOT RanOnce THEN
  13.     RanOnce = -1
  14.     FOR i = 4 TO 100
  15.         '_LIMIT 25
  16.         F = _LOADFONT("cour.ttf", i, "monospace")
  17.         FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
  18.         _FREEFONT F
  19.     NEXT
  20. IF percent = 0 THEN EXIT SUB
  21. desiredscale = (percent / 100) * h
  22. FOR i = 5 TO 100
  23.     IF FontSize(i) > desiredscale THEN EXIT FOR
  24. Ftemp = _FONT
  25. F = _LOADFONT("cour.ttf", i - 1, "monospace")
  26. IF Ftemp <> 16 THEN _FREEFONT Ftemp
  27.  
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 15, 2018, 09:54:33 pm
Quote
I can get your original program to run without _LIMIT 25 if I add a delay after line 2.

Which just gives us another fringe case of "sometimes works, sometimes doesn't".  For my purpose, the easiest solution right now is to just add the delay, read the size once, and then print it to a CSV text file.  After that, I can import the sizes as DATA and skip the font loading routine completely.

It's easy enough for me to do a work-around, but that'd do nothing to address the actual glitch in _LOADFONT.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 10:11:14 pm
The bug seems to be that _FONT _LOADFONT("cour.ttf", 16, "monospace") needs to be completed before the sub containing more font calls is called. Actually, just adding a PRINT statement after that statement, with no delay, will make the program work, too. In QB64, if the _LOADFONT statement could be placed into a loop and not exited until the font was loaded, that should fix the problem.

BTW, CLEAR is as buggy as RUN with the STATIC statement.

Pete
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Cobalt on November 15, 2018, 10:37:49 pm
As I mentioned on the previous page, it's a _LOADFONT issue.  All you need to see the issue is:
FOR I = 1 TO 100
    F = _LOADFONT("cour.ttf", i, "monospace")
NEXT

so you did, sorry I must admit to just scanning the posts and not thoroughly reading them.

Could it be that _LOADFONT is still accessing memory when the next call comes a long and tries to access the same memory(or part of it) at the same time causing it to crash? maybe we need to add some kind of check to make sure the previous action was completed before the next one starts?
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 15, 2018, 11:08:30 pm
Yeah, that's what I said, too.

Well, I made an auto-run version but even with the _DELAY after line 2, it still failed, but it took 30 minutes to do so. This reminds me of using cURL where different lag times require you check to see if the process has completed before leaving the polling loop.

Code: QB64: [Select]
  1. REDIM SHARED FontSize(4 TO 100)
  2. _FONT _LOADFONT("cour.ttf", 16, "monospace")
  3. _DELAY .25
  4. ScaleScreen 0 'initialize the font settings
  5.  
  6. PRINT "Hello World"
  7.  
  8. ScaleScreen 50
  9. ScaleScreen 200
  10. ScaleScreen 150
  11.  
  12. SUB ScaleScreen (percent AS INTEGER)
  13. STATIC RanOnce
  14. IF NOT RanOnce THEN
  15.     RanOnce = -1
  16.     FOR i = 4 TO 100
  17.         '_LIMIT 25
  18.         F = _LOADFONT("cour.ttf", i, "monospace")
  19.         FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
  20.         _FREEFONT F
  21.     NEXT
  22. IF percent = 0 THEN EXIT SUB
  23. desiredscale = (percent / 100) * h
  24. FOR i = 5 TO 100
  25.     IF FontSize(i) > desiredscale THEN EXIT FOR
  26. Ftemp = _FONT
  27. F = _LOADFONT("cour.ttf", i - 1, "monospace")
  28. IF Ftemp <> 16 THEN _FREEFONT Ftemp
  29.  
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: luke on November 16, 2018, 04:04:46 am
Minimal test case:
Code: QB64: [Select]
  1. _FONT _LOADFONT("c:\windows\fonts\cour.ttf", 16, "monospace")
  2. FOR i = 1 TO 100
  3.     F = _LOADFONT("c:\windows\fonts\cour.ttf", i, "monospace")
The "monospace" on the second _LOADFONT is required so the issue is likely with the character width calculation routine.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: luke on November 16, 2018, 04:38:33 am
Actually it can be reduced to just two lines, as long as you're willing to run it sufficiently many times:
Code: QB64: [Select]
  1. _FONT _LOADFONT("/media/winmain/Windows/Fonts/cour.ttf", 16, "monospace")
  2. F = _LOADFONT("/media/winmain/Windows/Fonts/cour.ttf", 12, "monospace")

EDIT: The location it ostensibly crashes at in FT changes each time. Fascinating.

EDIT 2: It even crashes if compiled with $console:only. At least it's not the glut thread messing things up.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 16, 2018, 07:35:29 am
And, oddly enough, I can get it to run 99.9% of the time with something as simple as:

FONT _LOADFONT("/media/winmain/Windows/Fonts/cour.ttf", 16, "monospace")
_DELAY 0.01
F = _LOADFONT("/media/winmain/Windows/Fonts/cour.ttf", 12, "monospace")

That 0.01 pause is enough on my PC to correct whatever the glitch is.  It's truly rare for it to fail after that (once every half hour of continuous looping for Pete; I have yet to experience another crash with _DELAY in there).

The issue with that sort of fix is others may not have the same speed/performance on their machines, so that delay may not be sufficient for them.  Others may not need that much delay, which means it could unnecessary lag up their programs.

I'm still digging...
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: TempodiBasic on November 16, 2018, 01:42:41 pm
Hi
please with what QB64IDE version is the issue coming out?
I've got a very different experience in my TOSHIBA i3 4GB RAM Windows 10 e QB64IDE version 1.2 revision [dev build] from git e490b1a !

Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 16, 2018, 02:44:58 pm
The latest dev build, as well as the stable build have the issue for me.  I haven't tried any older ones.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: TempodiBasic on November 16, 2018, 02:50:23 pm
I have no issue after REMMED  _LIMIT 25

here the code I use
Code: QB64: [Select]
  1. DIM NAMEF$, q AS LONG, F AS LONG
  2.  
  3. NAMEF$ = "C:\Windows\Fonts\arial.ttf" 'micross.ttf"
  4. 'JAVATEXT.TTF" 'GABRIOLA.TTF" 'LUCON.TTF" 'impact.ttf"
  5. q = _LOADFONT(NAMEF$, 16, "monospace")
  6.     _FONT q
  7.     PRINT q
  8. ScaleScreen 0 'initialize the font settings
  9.  
  10. PRINT "Hello World"
  11.  
  12. ScaleScreen 50
  13. ScaleScreen 200
  14. ScaleScreen 150
  15.  
  16.  
  17.  
  18.  
  19.  
  20. SUB ScaleScreen (percent AS INTEGER)
  21.     STATIC FontSize(4 TO 100), RanOnce
  22.     SHARED F AS LONG, NAMEF$
  23.     IF NOT RanOnce THEN
  24.         RanOnce = -1
  25.         FOR i = 4 TO 100
  26.             '            _LIMIT 25
  27.             F = _LOADFONT(NAMEF$, i, "monospace")
  28.             IF F > 0 THEN
  29.                 FontSize(i) = _FONTWIDTH(F)
  30.                 _FREEFONT F
  31.             ELSE
  32.                 PRINT F 'make and keep an array of font sizes so we don't have to keep loading them over and over
  33.             END IF
  34.         NEXT
  35.     END IF
  36.     IF percent = 0 THEN EXIT SUB
  37.     h = _FONTWIDTH
  38.     desiredscale = (percent / 100) * h
  39.     FOR i = 5 TO 100
  40.         IF FontSize(i) > desiredscale THEN EXIT FOR
  41.     NEXT
  42.     Ftemp = _FONT
  43.     F = _LOADFONT(NAMEF$, i - 1, "monospace")
  44.     _FONT F
  45.     IF Ftemp <> 16 THEN _FREEFONT Ftemp
  46.  
it is your code with some control to get no error rising up from a loading error like a file not found!
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: TempodiBasic on November 16, 2018, 03:10:30 pm
about Luke minimal test I got these result
1. no error
2 error if I add these lines of code

Quote
print i; " ";
_freefont F

here whole code
Code: QB64: [Select]
  1. _FONT _LOADFONT("c:\windows\fonts\cour.ttf", 16, "monospace")
  2. FOR i = 1 TO 100
  3.     F = _LOADFONT("c:\windows\fonts\cour.ttf", i, "monospace")
  4.     PRINT i; " ";
  5.     _FREEFONT F
  6.  

moreover
using  _DELAY 0.01 or _DELAY 0.1 before the FOR has no results
while using this _DELAY after _FREEFONT F in the FOR loop
it lets to work the program with no error....
It may be a latency about the malloc work behind _LOADFONT  and _FREEFONT...
what do you think about it?
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 16, 2018, 04:10:04 pm
@Tempodi -- That's the issue with these type of race conditions; they're intermittent and hard to trace/duplicate.  Your PC may be fast enough (or slow enough) that it might never experience the issue. 

Seems like what we're dealing with is a race condition where the _FONT routine is doing something which ends up erroring out when it finally finishes in the _LOADFONT routine.  The pause after _FONT allows it to finish what it's doing before _LOADFONT starts.

The only issue with a set time for a pause is how long to make that pause.  Different PCs may resolve the race condition at different times, so a set pause isn't the ideal solution.  What we need is to find the root of the issue and then trap it at the source.

So, for now, we're still digging and looking for the final source of the issue.  ;)
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: Pete on November 16, 2018, 07:22:04 pm
Hi
please with what QB64IDE version is the issue coming out?
I've got a very different experience in my TOSHIBA i3 4GB RAM Windows 10 e QB64IDE version 1.2 revision [dev build] from git e490b1a !

I get the error at random times in QB64 v 1.1 on Win 10. I made an auto-run version of Steve's program and noticed that you can increase the delay times but eventually you get a crash. It could take hours, but it will happen. The solution is to keep the font statement in a loop until it completes. That would mean making something whatever library the font statements are in to handle that. That's above my pay grade, as I don't dabble in C/C++ programming.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: SMcNeill on November 16, 2018, 07:51:28 pm
I'm not so certain we need a loop at the _FONT statement, so much as we may need to set a flag there (FontInUse) and then pause LOADFONT to stop it from running until the flag is cleared.  Due to multi threads, pausing the end of _FONT may not be as useful as pausing the start of _LOADFONT, until it's finished.

Let's see what Luke and Fell come up with, over the next few days.  I can't seem to pinpoint the issue, so maybe they'll have a little better luck with it.
Title: Re: Repeated calls to _LOADFONT with "monospace" can crash
Post by: moises1953 on May 15, 2020, 05:02:38 am
_LOADFONT needs the use of style$ variable, not a constant.
This example works OK:
Code: QB64: [Select]
  1. 'MultipleFontLoad
  2. 'SCREEN 0 may use only one FONT. When changed, changes full screen
  3. 'Otherwise graphic modes preserve the screen contents when change font
  4. '_LOADFONT needs the use of style$ variable instead of constant
  5. CONST MINSIZE = 8, MAXSIZE = 100
  6. DIM i AS INTEGER, hFont(MAXSIZE) AS LONG
  7. f$ = "cour.ttf"
  8. style$ = "MONOSPACE"
  9.  
  10. PRINT "LOADING:"; f$;
  11. FOR i = MINSIZE TO MAXSIZE
  12.   PRINT i;
  13.   hFont(i) = _LOADFONT(f$, i, style$)
  14.   IF hFont(i) <= 0 THEN EXIT FOR
  15. IF i > MAXSIZE THEN
  16.   DO
  17.     PRINT "Font sizes:"; MINSIZE; "-"; MAXSIZE;
  18.     INPUT ". Select size"; fontsize%
  19.     IF fontsize% < MINSIZE OR fontsize% > MAXSIZE THEN EXIT DO
  20.     _FONT hFont(fontsize%)
  21.   LOOP
  22.   PRINT "Fail"; i; hFont(i)
  23.  
  24. FOR i = MINSIZE TO MAXSIZE
  25.   _FREEFONT hFont(i)
  26.  
  27.