mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

dxCreateFont randomly creates fonts with wrong characters

Open MrDadosz opened this issue 1 year ago • 8 comments

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

  • [X] I have read and understood the Security Policy and this issue is not security related.

MrDadosz avatar Feb 29 '24 20:02 MrDadosz

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")

Xenius97 avatar Mar 08 '24 19:03 Xenius97

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.

MrDadosz avatar Mar 10 '24 23:03 MrDadosz

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.

FileEX avatar Mar 12 '24 12:03 FileEX

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

MrDadosz avatar Mar 12 '24 17:03 MrDadosz

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

JeViCo avatar Mar 14 '24 13:03 JeViCo

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

MrDadosz avatar Jul 28 '24 21:07 MrDadosz

Please attach a test resource along with the specific font

FileEX avatar Jul 28 '24 21:07 FileEX

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.

MrDadosz avatar Jul 28 '24 22:07 MrDadosz

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

jayceon123 avatar Aug 28 '24 19:08 jayceon123