(原)多线程sdl_ttf显示文字
最近在使用sdl做视频显示,因为需要显示文字,所以就找了sdl的拓展库,sdl_ttf来做文字显示。
这里说明一下:sdl_ttf不支持多线程,官方上面有说明,它不是多线程安全的。
所以当我最初使用sdl_ttf来做多线程显示文字的时候,就会出现崩溃的问题。
崩溃的地方老是出现在:FT_Load_Glyph这个函数。
然后我就发现,原来sdl_ttf不支持多线程,而sdl_ttf下的freetype它其实也是非多线程安全的,也只单线程使用。
同时在查找的过程中,我找到了几个很有用的帖子,这里贴出来给大家:
https://bugs.launchpad.net/ubuntu/+source/freetype/+bug/1199571
其中有人在多线程中使用freetype出现崩溃,然后把其作为Bug反馈给了freetype开发团队,上面就是Bug的反馈原内容。
然后还有这个:https://github.com/behdad/ftthread
这里是一个多线程测试freetype的tools,它是基于linux环境的。
我把帖子的内容贴出来:
ftthread
======== This is a test tool to use FreeType2 in a multi-threaded environment. FreeType2 is not thread-safe, and the original author(s) of FreeType
suggest that one FT_Library per thread should be used. Unfortunately
this is too inflexible to be really useful. However, there are ways to use it safely in a multi-threaded environment
with simple modifications to FreeType. I have now produced a complete
patchset to that effect and tested it using this utility. The patchset
is available here: https://github.com/behdad/freetype/commits/ftthread and I hope it to be integrated into upstream FreeType very soon. In
the mean time, here's the new threadsafety model, which needs to be
integrated into FreeType documentation. Note that cairo graphics
library already uses FreeType in this way and as such the entire GNOME
desktop has been relying on this model, to huge disappointment as seen
in the following bug reports, each of which have many duplicates: https://bugzilla.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=69034 Threadsafety model
================== - A FT_Face object can only be safely used from one thread 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
only be done from one thread at a time. Discussion
========== In this model, one can use a single FT_Library object across threads as
long as a mutex lock is used around FT_New_Face / FT_Done_Face. Any calls
to FT_Load_Glyph and similar API are safe and do not need the lock to be
held as long as the same FT_Face is not used from multiple threads at the
same time. Note that this goes almost all the way to making FreeType API useful from
multiple threads. The only remaining bit is the unfortunately API that is
FT_Library_SetLcdFilter (and to less extent FT_Library_SetLcdFilterWeights). I will try to work out a solution for replacing FT_Library_SetLcdFilter
using new FT_LOAD_* values. There seem to be quite a few bits available in
that space, so that work should happen soon.
文中指出,freetype是非多线程安全的,同时他对于使用多线程的环境下,提出了自己的使用安全模型,并给出了代码。
按照他的示例代码,我对sdl_ttf的源码进行修改,是sdl_ttf适应多线程。
(原)多线程sdl_ttf显示文字的更多相关文章
- SDL显示文字
前面教程里,我们只显示图片,没提到如何显示文字, SDL本身没有显示文字功能,它需要用扩展库SDL_ttf来显示文字.ttf是True Type Font的缩写,ttf是Windows下的缺省字体,它 ...
- 实现password框中显示文字提示的方式
其实实际上实现中并不能让password中显示文字提示,但是我们在工作中有这样的需求,当没输入东西的时候,框内有提示输入密码,但是当输入东西的时候又显示的是*号,那么是如何实现的呢?其实原理很简单,就 ...
- Android 使用Font Awesome 显示文字图标
Android 使用Font Awesome 显示文字图标 简单几步就可以完成 简单的效果图: 1. 创建 assets 文件夹 在Android Studio 上的创建步骤为: 在 src/main ...
- 根据html容器大小和显示文字多少调节字体大小
在做html相关的东西的时候经常会遇到这样的问题,容器大小(长x宽)固定,容器包含内容(特指文字)多少不固定,这个时候就让人很苦恼了,将字体大小设置成多少才合适呢?下面看看我的解决思路: 首先要知道网 ...
- (委托事件处理)关于多线程执行显示进度条的实例(转)&&线程间操作无效: 从不是创建控件“rtxtEntryNO”的线程访问它。
关于多线程执行显示进度条的实例! 之前回答了一篇关于怎么在线程中操作进度条的帖子,估计有人看的不是很明白今天没事,写了一个小小的实例,很简单,就2个文件权当抛砖引玉,希望有更好解决方案的人发表一下意见 ...
- Qt中在图片上叠加显示文字
Qt中在图片上叠加显示文字 QCustLabel::QCustLabel(QWidget *parent):QLabel(parent){ setPixmap(QPixmap(QString::f ...
- 动态更新Toolbar Menu以及Menu中同时显示文字和图标
动态更新Toolbar Menu以及Menu中同时显示文字和图标 我们经常会有这样的需求,在切换Fragment或者点击某个按钮后动态更新Toolbar上Menu项.但是onCreateOptions ...
- 解决TextView在显示文字的时候,一行还没显示满就跳到下一行
转载请注明:转自 http://blog.csdn.NET/u011176685/article/details/48295185 一.问题描述: Android的TextView在显示文字的时候,如 ...
- ActionBar只显示图标不显示文字
问题:ActionBar菜单项android:showAsAction设置为android:showAsAction="always|withText"或者android:show ...
随机推荐
- python 三元表达式 if for 构建List 进阶用法
1.简单的for...[if]...语句 Python中,for...[if]...语句一种简洁的构建List的方法,从for给定的List中选择出满足if条件的元素组成新的List,其中if是可以省 ...
- [转] lua 获取本地当月天数
亲测,无误. 原文传送门:lua 获取本地当月天数 开发中有用到,记录一下. local year,month = os.date("%Y", os.time()), os.dat ...
- 【转】Unity3D的LightProbe动态光探头用法介绍
原创至上,移步请戳:Unity3D的LightProbe动态光探头用法介绍 之前曾经介绍过Unity3D的LightMapping烘焙的用法.单独使用的LightMapping效果很好,但由于只是把光 ...
- 【机器学习】粗糙集属性约简—Attribute Reduction
介绍 RoughSets算法是一种比较新颖的算法,粗糙集理论对于数据的挖掘方面提供了一个新的概念和研究方法.本篇文章我不会去介绍令人厌烦的学术概念,就是简单的聊聊RoughSets算法的作用,直观上做 ...
- 使用 libvirt创建和管理KVM虚拟机
1. libvirt介绍 Libvirt是一个软件集合,便于使用者管理虚拟机和其他虚拟化功能,比如存储和网络接口管理等等.Libvirt概括起来包括一个API库.一个 daemon(libv ...
- java 泛型详解-绝对是对泛型方法讲解
Reference: http://blog.csdn.net/s10461/article/details/53941091 1. 概述 泛型在java中有很重要的地位,在面向对象编程及各种设计模 ...
- plsql 安装后database下拉没有东西(转)
转载自:http://www.cnblogs.com/yaobolove/p/5682982.html 今天来说一下问题,就是装了plsql竟然在database这一栏没有东西,我也是纠结了很久,感觉 ...
- Mybatis 返回插入的主键
业务中,会遇到这样的问题,就是感觉返回的主键,插入作为其他表的外键. 那么问题来了,如何去实现,其实方法比较简单,这里就是重点记录下,会出现的误区. 用自动生成sql工具的话,加上下面这句话 < ...
- [转]PowerDesigner中name和code取消自动关联
PowerDesigner中,但修改了某个字段的name,其code也跟着修改,这个问题很讨厌,因为一般来说,name是中文的,code是字段名. 解决方法如下: 1.选择Tools->Gene ...
- OAuth2.0 授权的工作原理
作者:Barret李靖链接:https://www.zhihu.com/question/19781476/answer/81020455来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...