Question can look weird, but I don’t know how to describe it better
I think there is a bug with AdvancedDynamicTexture. Or maybe I use it wrong, because I cannot reproduce it in PlayGround.
Problem: I use gui with custom font. It works. But sometime it glitches, font became standard and then back to custom. On the video I can reproduce it by resizing window (there is no cursor, but hope you can see it). It only happen once after creation of ADT. One resize - it brake - second - fix.
And I cannot force it to reproduce with code, only by resizing manually. But sometime it happen when I add controls dynamically to ADT (on the video content is loaded from json).
Also there is another problem (maybe another bug). If I manage to “brake” font before something updates ADT, then it updates, font fixes, but rects use wrong size and text cut off. Of course it happens only if useInvalidateRectOptimization is true. Video:
So maybe it’s a bug. Or I can do something to workaround?
Are we talking iOS here or is it a common issue?
Did you search the forum? I remember some discussions around a similar topic but would need to find’em again. Let me/us know if you don’t manage to find the answer to your issue.
Edit: Quickly made a search through my msg. You might find your answer with this thread (or not?)
Yes, I also had that other piece of code. I’m glad it worked for you (sort of).
My apologies. I thought it would also be in the thread I shared… but apparently, it was elsewhere So, thx for sharing it again
As for the gui update, I also remember we kind of discussed it before. Sadly, my small brain doesn’t remember the outcome So, let’s ask again our gui-angel cc @carolhmj
Edit: Thinking of it a bit further with a delay may be I sort of remember it could be something around cross-origin and CORS policies. I kind of remember that when this happend to me, if I reload the scene, on the second time the font (eventually) makes it through and displays correctly (even on resize).
Using the FontFace is the right move here because it guarantees the font is there before the GUI/Canvas tries to use it, otherwise, it will depend on the browser behavior. I wonder if the case with resize is for some reason trying to load the font again, and that’s why it switches back to default for a frame. Could you share a reproduction of your project? It doesn’t need to be the full project, just this part with the font.
I will let @carolhmj have a look at your project since I know **** about Vite
Just wanted to ask (while waiting because it’s the weekend and also holidays period)
…Did you actually check with some other font and did you try to specify the fontWeight?
Yes,sure. But if there’s anything specific for running the project with Vite, I will likely not be able to detect it. That would be a waste of time (for both of us). I don’t think you need me to make further ‘assumptions’ so I’d rather have you wait on the feedback from someone who knows.
Yes sure. But hope it’s not related to Vite, as I had this bug on another hosting, not only locally.
Now I tried to check another font, and cannot reproduce issue again (with previous font too). But then tried another browser - and it’s here, but this time font looks like not loaded for first render and appears only after resize.
So now I think, that it’s related to some browser cache? Maybe font caches somehow and loaded (for the first time), but it’s not loaded for real, that’s why on next resize it brakes, and then fixes again. Weird.
Same for another font. So I think it’s related to loading\cache, and not to font itself.
But maybe there is still some bug. Who knows. Thank you anyway, as we found solution/workaround at least.
Thanks for the feedback,
The reason I was asking this is because I created some fonts myself. Ages ago. But the font format is still unchanged. I sort of remember I eventually had issues (including in css) with the naming of fonts. Font name, family name, ps name, font type and font style. I guess you didn’t download and integrate the entire family of this font. Only the bold version style. That’s why I suspected that eventually a fallback towards the regular version is eventually called at some point. Reason why I asked you to check with another font. I would try to either
Get and serve the regular version of the font and put it as a fallback, first in the list.
Add fontWeight and make sure you use the correct style name, gathered from the font info. It could be ‘bold’ or ‘700’ or ‘700 bold’, honestly I didn’t check.
Put the url in full in the source to avoid any potential blocking when reading the font url.
If you can find or convert it, use the .otf version of font.
May be any of these will help. Meanwhile, have a great day
From this explanation on MDN: MDN (mozilla.org), it seems like preloading a font requires us to add this “crossorigin” attribute to it. After doing that, the font is loading as expected every time. And there’s not even need of that hidden div, it seems the @font-face declaration on the CSS is enough for making the font available to the canvas.
Sounds good, as it would be great to not have code, that must wait for font loading.
So I tried it now. And it’s working in Chrome (I think you used it), but not working in Firefox (I use it as main browser).
In Firefox font is loaded, but after creation of adt (I think so), because at first the font is standard, and after resize it changes to custom.
I have turned on “disable cache” in both browser, if it matters.
If it isn’t related to resizing and custom fonts, it’s better to make one topic per specific issue.
It’s easier to track and solve’em and depending on what it is, it might involve different people.
If I can ask you to kindly do that? You can still link it to another post if it’s part of a more global thingy.
That would be my suggestion.