While I am not an expert at the low level IO on iOS/Android, my guess is your loop is using up all the available file handles in the system, since it is looping fast and loading them all from the files.
Another option might be to create BitmapFonts instead of using the TTF files and load them into texture memory and access them that way--you can of course also scale then instead of directly using different font sizes I would suppose.
Also, forgot to mention, my real game doesn't do this. It's loading fonts after several seconds, and still throws that error on around ~ 10 loads. This was just a reduced test case.
Another option might be to create BitmapFonts instead of using the TTF files and load them into texture memory and access them that way--you can of course also scale then instead of directly using different font sizes I would suppose.
Do BitmapFont's scale method scale fonts perfectly? No pixelation?
Ok, now this is weird. I ran the program a few times. Here's the output.
Uploading finished.
1234567891011121314
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
12345678910111213
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
123456789101112
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
1234567891011
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
12345678910
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
123456789
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
12345678
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
1234567
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
123456
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
12345
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
1234
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
123
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
Uploading finished.
12
main.lua:5: foo.ttf: No such file or directory.
stack traceback:
foo.ttf is uploading.
main.lua is uploading.
Uploading finished.
It's like the program is "running out of fonts" after every start. The program crashed every time, except the last. Gideros Player crashed on the last try.
Weird really, just to stress test i run this code many times in my player and no errors. All prints are perfect. I will continue to test with it if i will receive any error i will inform here.
local font,font2,font3,font4
for i =1, 2000doprint(i)
font = TTFont.new("Roboto-Regular.ttf", i)
font2 = TTFont.new("Turkish_Times_New_Roman.ttf", i)
font3 = TTFont.new("Roboto-Regular.ttf", i)
font4 = TTFont.new("Turkish_Times_New_Roman.ttf", i)end
@___ i agree after this post i increased my stress tests counter to 5000 and runs more than 10 times and no errors at all. Maybe something wrong with the ttf font it self or the folder that it is staying?
did you try it in real device? for exaple make a button and try many times? Maybe it is player problem only? Because as i said i tried in my gideros studio many times i am not receiving any errors? Maybe you have some extra code, if you send me your project i can try it.
@___ i make it 100000 and receive this error more than 2 times.(Can not check all it is so long:D) main.lua:5: Roboto-Regular.ttf: Error while reading font file. stack traceback: main.lua:5: Roboto-Regular.ttf: Error while reading font file. stack traceback: It is weird from this test i understand that this error is generated randomly.
There is definitely a bug here. Most probably, TTFont keeps the file open and OS run out of file handles when TTFont's aren't collected fast enough. I'll look at it and post an update here.
I don't think that would explain the fact that my game used to crash with the font just being loaded 10-12 times, with the exact same message? That too, with several seconds gap in between.
Uncomment the line to make sure the garbage amount is fairly constant and doesn't 'run away'. You can regulate it by changing the 1000 setting for setstepmul.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Comments
Anyway way don't you just load all your fonts into globals at runtime and just access them?
_G["font1"] = TTFont.new("font1.ttf, 1)
_G["font2"] = TTFont.new("font2.ttf, 2)
etc..
Just an option.
Just wanted to know why this was throwing an error.
Also, if I were using 70 sizes, wouldn't that also throw an error?
Another option might be to create BitmapFonts instead of using the TTF files and load them into texture memory and access them that way--you can of course also scale then instead of directly using different font sizes I would suppose.
Started Player again, runs upto 200 fine. Tried about 10 times.
But I did restart the player yesterday too, it was still giving the errors.
Something is definitely wrong.
Just downloaded PT Sans from http://www.fontsquirrel.com/fonts/PT-Sans , and used PTC55F.ttf
First run - 181, second run - 180, third run - 179, ...
And the folder is the root folder in this test, and /resources/fonts/ in my real game. So can't be that either.
My Apple dev account is pending approval, so I cannot test on a real device yet
Can you try increasing i's limit to maybe a million? See if it crashes anytime soon?
i make it 100000 and receive this error more than 2 times.(Can not check all it is so long:D)
main.lua:5: Roboto-Regular.ttf: Error while reading font file.
stack traceback:
main.lua:5: Roboto-Regular.ttf: Error while reading font file.
stack traceback:
It is weird from this test i understand that this error is generated randomly.
I got "No such file or directory."
Thank you very much for detailed analysis
I don't think that would explain the fact that my game used to crash with the font just being loaded 10-12 times, with the exact same message? That too, with several seconds gap in between.
Likes: Apollo14
https://deluxepixel.com