Menu

"Failed to create font" after several calls

Help
tanh
2018-02-08
2018-02-10
  • tanh

    tanh - 2018-02-08

    After several Easybox calls (500 - 800), the script aborts with a fatal error. The calls are made from a function. Running the script on Windows 10, PEBL 2.0 on diverent hosts with the same error.

    Is there any workaround? Thanks in advance.

    from stderr.txt with comments:
    "Called from function [] on line [306] of file [.\Klangfarben_debug_06.pbl] (function call)
    Called from function [] on line [410] of file [.\Klangfarben_debug_06.pbl] (EasyLabel("text", gXc, gYc + ToInteger(gTH/2), gWin, 30))

    Error near line 451 of file C:_Programme_\PEBL2\bin..\pebl-lib\Utility.pbl: (Makefont)
    Failed to create font"

    Exiting PEBL because of captured signal."

    stdout.txt:
    "SUCCESS at getting display mode?:0
    1920,1080,60
    Initializing 3440--1440
    Driver name (0): direct3d
    Driver name (1): opengl
    Driver name (2): opengles2
    Driver name (3): software
    Proband Nr. 26
    Oh My Goodness, an error : [Passed a NULL font source]"

     
  • Shane T Mueller

    Shane T Mueller - 2018-02-09

    This is something I knew was happening on PEBL 0.14--it caused me some problems a few years ago because essentially my experiment stopped after a fixed number of trials. My response is based on my memory from trying to figure it out then. I was hoping that this would magically fix itself when I moved to SDL2, but it looks like it did not.

    The problem comes because fonts that are created don't cleanly give up their file handle when the font goes away. As far as I can tell, it is a memory-leak type error, but I think it is happening deep within the SDL_ttf library, so the best approaches require either fixing the library or building a complex workaround within PEBL compiled code. Because it is not letting go of the file handle, eventually the PEBL application reaches an OS limit on the number of files it can simultaneously load. In my memory, this is around 600, which matches what you are reporting above. The basic workaround is to make sure you don't open more than that many font files per experiment.

    It might seem easy to do that, but the issue comes when a task creates its text labels within a trial. This definitely happens when you use the EasyLabel and EasyTextBox functions--it creates a new font every time you do that. So, if you have a task with 4 labels on the screen on each trial (maybe a stimulus, a header, footer, and feedback), then 100 consecutive trials of that would open the same font file 400 times, and 200 trials would probably hit the limit. I'm guessing this basically describes what is going on in your experiment. Creating a font new font for every label seems inefficient, but the time and memory overhead on modern computers is really quite small for this and it is rarely a problem, so I never tried to work out a more efficient method where PEBL would detect you are trying to open a font that is already open and try to reuse it. I may try to do that for the next release.

    Anyway, the workaround you can use is to create a global font outside of the trial structure using MakeFont(), and then reuse that with MakeLabel() instead of EasyLabel. Thus, make the font just once, but use it as many times as you need. You basically just need to avoid opening a font file too many times. If you need any tips, reply here with code examples.

     
  • tanh

    tanh - 2018-02-10

    Thank you for the quick and detailed answer. Your explanation helped me a lot. Today I was able to change the script from EasyLabel to MakeLabel. It works great. Thank you very much.

     

Log in to post a comment.

MongoDB Logo MongoDB