(original) Multi-threaded SDL_TTF display text

Source: Internet
Author: User

Recently in the use of SDL to do video display, because the need to display text, so we found the SDL Development Library, Sdl_ttf to do text display.

Here is a note: Sdl_ttf does not support multi-threading, the official above is described, it is not multithreaded security.

So when I first used Sdl_ttf to do multi-threaded display text, there was a crash problem.

The place that crashes is always present: ft_load_glyph this function.

Then I found that the original Sdl_ttf does not support multi-threading, and Sdl_ttf under the FreeType it is actually non-multithreaded security, but also only single-threaded use .

At the same time in the process of finding, I found a few useful posts, which are posted here to everyone:

https://bugs.launchpad.net/ubuntu/+source/freetype/+bug/1199571

One of them used FreeType crashes in multi-threading, and then gave it back as a bug to the FreeType development team, which is the original content of the bug's feedback.

And then there's this: Https://github.com/behdad/ftthread

Here is a multi-threaded test freetype tools, which is based on the Linux environment.

I posted the contents of the post:

Ftthread========this is a test tool to the use of FreeType2 in a multi-threaded environment.FreeType2 is isn't thread-safe, and the original author (s) of freetypesuggest that one ft_library per thread should bes u  Sed. Unfortunatelythis is too inflexible to be really useful.However, there is ways to use it safely in a multi-threaded environmentwith simple modifications to FreeType. I has now produced a completepatchset to the effect and tested it using this utility. The Patchsetis available Here:https://github.com/behdad/freetype/commits/ftthreadand I hope it to being integrated into UPS  Tream FreeType very soon.  Inthe mean time, here's the new threadsafety model, which needs to beintegrated into FreeType documentation. Note that Cairo Graphicslibrary already uses FreeType in this and as such the entire gnomedesktop have been relying on This model, to huge disappointment as Seenin the following bug reports, each of which has many Duplicates:https://bugzi lla.redhat.com/show_bug.cgi?id=678397 https://bugzilla.redhat.com/show_bug.cgi?id=1004315 https:// bugzilla.redhat.com/show_bug.cgi?id=1164941 https://bugzilla.redhat.com/show_bug.cgi?id=1165471 https:// bugs.freedesktop.org/show_bug.cgi?id=69034threadsafety model==================-A Ft_face object can only is safely used from one th  Read at a time.  -A Ft_library object can be used without modification from multiple threads at the same time. -Ft_face creation/destruction with the same Ft_library object can is only is done from one thread at a time. Discussion==========in this model, one can use a single Ft_library object across threads Aslong as a mutexes lock is used AR  Ound Ft_new_face/ft_done_face. Any Callsto ft_load_glyph and similar API was safe and do not need the lock to beheld as long as the same ft_face was not u Sed from multiple threads at thesame time.  Note that this goes almost all the making FreeType API useful frommultiple threads. The only remaining bit is the unfortunately API, the isft_library_setlcdfilter (and to less extent Ft_library_setlcdfilter Weights).  I'll try to work out a solution for replacing ft_library_setlcdfilterusing new ft_load_* values. There seem to being quite a few bits available inthat space, so the work should happen soon.

It is pointed out that FreeType is non-multithreaded security, and he puts forward his own security model in the use of multi-threaded environment, and gives the code.

According to his example code, I sdl_ttf the source code to modify, is sdl_ttf to adapt to multithreading.

(original) Multi-threaded SDL_TTF display text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.