Crash on Chinese unicode font

Issue #1213 resolved
Walter Stanish
created an issue

I am trying to localize my game for Chinese.

The font I am using is from

It looks very good and clear at 16px.

With the font file from the above URL and following program executed as 'main.lua fireflysung.ttf 你好', the font loads, glyphs display, but then Love crashes. However, the same program with 50+ other (non-Chinese) fonts works fine.

#!/Applications/ .
fontfile = ""
font = nil
example_type = ''

function love.load()
        fontfile = arg[3]

        example_type = arg[4]

-- set highest available resolution
        modes = love.window.getFullscreenModes()
        table.sort(modes, function(a, b) return a.width*a.height < b.width*b.height end)
        v = modes[#modes]
        screenModeFlags = {fullscreen=true, fullscreentype='desktop', vsync=true, msaa=0}
        love.window.setMode(resolutionPixelsX, resolutionPixelsY, screenModeFlags)


function love.draw()
-- draw example text in different sizes
        for size=5,35,1 do
            font =,size)
            if example_type == '' then
                example_type = 'This is an example.'
   .. " " .. fontfile .. " " .. example_type,100,100+size*20)

Comments (10)

  1. Walter Stanish reporter

    Note that if I display example latin text with the font and don't use Chinese characters, it still crashes... and that the crash is not instant, it's delayed.

  2. Alex Szpakowski

    You're creating 30 new Font objects every frame – which loads 30 new 15MB font files from disk to RAM and allocates 30 new textures every frame (extremely expensive) without deleting the old un-referenced ones until a garbage collection cycle sometime in the future.

    What seems to be happening is the app runs out of RAM (and possibly VRAM) and once it can't evict any more allocated memory from other apps, it just shuts down (possibly inside FreeType's code).

    Ideally you should only create the Font objects once (usually at startup, or on-demand) and then reuse them instead of recreating them every time they're needed.

  3. Alex Szpakowski

    It's possible / likely that the font file in question is larger or has larger glyphs than the other font files you tested, so it might be running out of RAM/VRAM before the garbage collection cycle with that font file, and not the other ones.

  4. Log in to comment