Author Topic: Repeated calls to _LOADFONT with "monospace" can crash  (Read 56106 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #15 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #16 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #17 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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #18 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #19 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?
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #20 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #21 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #22 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

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #23 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.
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #24 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #25 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.  
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #26 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #27 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #28 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?
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Repeated calls to _LOADFONT with "monospace" can crash
« Reply #29 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.  
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/