| Summary: | strange bug with TTF_OpenFontIndexRW/TTF_OpenFontRW and render UTF8/Unicode string | ||
|---|---|---|---|
| Product: | SDL_ttf | Reporter: | ace <spam4ace> |
| Component: | misc | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | sylvain.becker |
| Version: | 2.0.15 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| URL: | https://discourse.libsdl.org/t/sdl-ttf-very-stange-bug-with-ttf-openfontindexrw-ttf-openfontrw-and-render-utf8-unicode-string/25809 | ||
| Attachments: | bug.c + PT Serif_Italic.ttf + Makefile | ||
|
Description
ace
2019-02-28 15:40:50 UTC
You need to rewind the RWops between the two calls of TTF_OpenFontIndexRW: SDL_RWseek(RWops, 0, RW_SEEK_SET); But I'm not sure why there was no error ... Thanks for your comment! Yes, it was solve problem in c, but SDL_RWseek() is macro, and unavailable in bindings (https://www.libsdl.org/languages.php) I think good solution will be: Calls SDL_RWseek() in TTF_OpenFontIndexRW/TTF_OpenFontRW AND/OR Replace this macro with function And I'm really was confused with original version of bug: https://drive.google.com/file/d/1COvG_VyOooe_fyu0p3DVbMZj8uMrnFL9/view In log at picture, after every line with "Rendering [...].." next line is "Font:NN ..." , where NN is ID in array of SDL_RWops, which used to render this line. I came to the conclusion that using SDL_RWseek(RWops, 0, RW_SEEK_SET) inside TTF_OpenFontIndexRW or TTF_OpenFontRW was bad idea, so i created feature request in SDL2 tracker to replace macros with functions: https://bugzilla.libsdl.org/show_bug.cgi?id=4526 I also think we shouldn't reset the RWops in SDL_ttf, because user can provide a concatenated ttf files. So I marked this as resolved. But I haven't understand the issue of your last link "original version of bug". If there is still a issue or not. So re-opened if this is a mistake. I thought this is a bug, because TTF_OpenFontIndexRW and TTF_OpenFontRW don't return NULL and generate error, if I give them RWops with position at the end of file. About "original version of bug": At this moment i am unable call SDL_RWseek(RWops, 0, RW_SEEK_SET) in my C# project. I use SDL_RWFromMem to create RWops, and i wondered why it works in this way? You can see that lines with style = 2,6,10,14 used same RWops(18) for TTF_OpenFontIndexRW, but bugged rendering only with style = 6 Or for example lines with style = 0, 4, 8, 12 - used same RWops(19) - but rendered without any problems. OR you can add make small change: if (position at the еnd of RWops) SDL_RWseek(RWops, 0, RW_SEEK_SET) It will be solve my problem and don't broken projects, which use this undetermined behavior. Not sure if you can always use SEEK_END eg detect the position at the end of rwops. For instance RWops could be a http stream (this extension: https://github.com/mgerhardy/SDL_rwhttp ) I look more in details. When it fails, it both: - returns 0 size metrics (except the advance which is correct) - returns 0 size after FT rendering. Those are valid datas .. (like a space) So for some reason, FreeType seems robust ... (maybe there would things to report to FT ... http://git.savannah.gnu.org/cgit/freetype/ ) What you can do maybe, is getting a new RWops from the same memory ? > What you can do maybe, is getting a new RWops from the same memory ? I implemented this already, but there is still a small memory leak - I couldn't call SDL_RWclose() cause it's macros :( I closing this issue: will be wait https://bugzilla.libsdl.org/show_bug.cgi?id=4526 ... or maybe make patch by myself (i need SDL 2.0.8, but if this feature request will be accepted, i think it will be only in next release). Thanks for your help!) I just realize that i could use freesrc=1, when calling TTF_OpenFontIndexRW, and this will be solve my problems at all. Thanks again! |