multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.42k stars 438 forks source link

dxCreateFont randomly creates fonts with wrong characters #3326

Open MrDadosz opened 8 months ago

MrDadosz commented 8 months ago

Describe the bug

dxDrawText using custom font created by dxCreateFont shows randomly wrong characters. Every script that I have is encoded in UTF-8. VRAM/RAM usage isn't limited. dxCreateFont returns font element, but it's looking like random characters without any reason. There is no problem with GUI fonts, only DX fonts. I tried different fonts but every font sometimes shows like example below. I even added timers and creation on event onClientResourceStart:

addEventHandler("onClientResourceStart", resourceRoot, function()
    setTimer(function()
        labelFont = exports["dadosz-fonts"]:loadDXFont("roboto", 20)
    end, 2500, 1)
end)

My main resource dadosz-fonts (resources don't destroy fonts):

function loadDXFont(fontName, size, scalable)
    if scalable then
        size = getFontSizeFromResolution(size) -- based on screen size
    end
    size = math.floor(size)
    if dxFonts[fontName] and dxFonts[fontName][size] then
        return dxFonts[fontName][size]
    end
    dxFonts[fontName] = dxFonts[fontName] or {}
    dxFonts[fontName][size] = dxCreateFont(fontName..".ttf", size, false, "proof")
    return dxFonts[fontName][size] -- returns font for another resource and multiple resources are using it for dxDrawText
end

Memory statistics (dxGetStatus):

memory left: 3096 MB
used memory by fonts: 69 MB
used memory by textures: 182 MB
used memory by rendertarget: 47 MB
Font GUI count: 19
Font DX count: 10

RAM used by gta_sa.exe: 1630 MB

Sometimes they look like this: https://i.imgur.com/ngJNlA8.png how they should look: https://i.imgur.com/LCzOkoF.png

Steps to reproduce

  1. join the server - mtasa://193.70.126.129:20000
  2. check fonts, if they are looking fine, do step 1
  3. random fonts are bugged - some are okay but not every font is okay

Version

Client: Multi Theft Auto v1.6-release-22388

Additional context

No response

Relevant log output

No response

Security Policy

Xenius97 commented 8 months ago

The problem is you create it in different resource. The solution is create in that resource which uses it like this:

dxCreateFont(":resource/font.ttf")
MrDadosz commented 8 months ago

It is not. I had problems with my minimap's resource so I made main resource.Previously, the problem also occurred even after setting the timer to 2500 milliseconds and using a font from the same resource. Now it uses less PC resources because I had multiple fonts created in multiple resources with same parameters. It works like 95% right, but there's 5% when it's rendering random characters. Random character like"B" sometimes could be "æ" and it will always be "æ" and only reconnect will help. Looks like sometimes it's using wrong characters, like you added +X offset to ASCII table.

FileEX commented 8 months ago

I think it's a problem with the font itself. I've never had this problem with random characters over the years, and I've used many different fonts.

MrDadosz commented 8 months ago

I'm using Roboto font and tried some others and I still have issues.

JeViCo commented 8 months ago

The exact same things happens to me with OpenSans font family downloaded from google

MrDadosz commented 3 months ago

Any ideas? That's happens a lot of time, not depending on VRAM usage, fonts are okay.

FileEX commented 3 months ago

Please attach a test resource along with the specific font

MrDadosz commented 3 months ago

dadosz-fonts.zip

There are problems with almost every font from this resource. I tried to load fonts with a timer, but it's not helping. I thought it would help when I create main resource for fonts but there's the same problem. In the past, almost every resource had .ttf inside, from +100 fonts to 30 fonts. Problem exists for more than 6 months.

local nametagFont = "default-bold"
addEventHandler("onClientResourceStart", resourceRoot, function()
    setTimer(function()
        nametagFont = exports["dadosz-fonts"]:loadDXFont("roboto", 10)
    end, 10000, 1)
end)

Sometimes it shows fonts, and sometimes it shows random characters from that font. I'm using roboto in most resources.

jayceon123 commented 2 months ago

Happened for me after a resource restart, then I was unable to delete the font file from the client cache, because "the file is open in System" and even needed to manually delete from the server/.../resource-cache/http-client-files/ directory because the server flooded with HTTP mismatch error