Active Forums > Bugs
Repeated calls to _LOADFONT with "monospace" can crash
SMcNeill:
--- Code: QB64: ---_FONT _LOADFONT("cour.ttf", 16, "monospace")ScaleScreen 0 'initialize the font settings PRINT "Hello World"SLEEP ScaleScreen 50SLEEPScaleScreen 200SLEEPScaleScreen 150SLEEP SUB ScaleScreen (percent AS INTEGER) STATIC FontSize(4 TO 100), RanOnce IF NOT RanOnce THEN RanOnce = -1 FOR i = 4 TO 100 _LIMIT 25 F = _LOADFONT("cour.ttf", i, "monospace") FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over _FREEFONT F NEXT END IF IF percent = 0 THEN EXIT SUB h = _FONTWIDTH desiredscale = (percent / 100) * h FOR i = 5 TO 100 IF FontSize(i) > desiredscale THEN EXIT FOR NEXT Ftemp = _FONT F = _LOADFONT("cour.ttf", i - 1, "monospace") _FONT F IF Ftemp <> 16 THEN _FREEFONT FtempEND SUB
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.
johnno56:
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
johnno56:
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?
FellippeHeitor:
No crash in Windows XP even with _LIMIT commented out. I assume you're on to a fix to it, Steve?
SMcNeill:
--- Quote from: 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?
--- End quote ---
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.
Navigation
[0] Message Index
[#] Next page
Go to full version