Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message boxes on X don't support UTF-8 #715

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Message boxes on X don't support UTF-8 #715

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2012-12-06 06:12:46 +0000, Sik wrote:

Created attachment 996
Broken message box screenshot

So, I updated to the latest snapshot (2.0.6713 as of today) and suddenly my game breaks - it can't initialize the video mode apparently. While I'm trying to figure out what's wrong with that, I also noticed another issue: the game was set to Japanese for whatever reason, and when the game tried to show the message box the output was completely mangled (see attached image). The game passes the error string as UTF-8, but it seems the message box is using a different encoding.

This is on Ubuntu 11.10 x86-64.

PS: the message should read "グラフィックモードをイニシャライズすることができませんでした。" if displayed properly.

On 2012-12-06 10:41:04 +0000, Sik wrote:

Upon further investigation, SDL seems to be using XDrawString, which takes in 8-bit characters. There's XDrawString16 which takes 16-bit characters, so that may be of some help though I have no idea how it handles the encoding.

Does anybody know how does X handle text encoding?

On 2012-12-06 11:14:19 +0000, Ryan C. Gordon wrote:

Yeah, we're using XFontStruct and XDrawString, we should be using XFontSet and XmbDrawString.

http://www.debian.org/doc/manuals/intro-i18n/ch-output.en.html

--ryan.

On 2012-12-07 17:04:22 +0000, Ryan C. Gordon wrote:

Should be fixed in hg changeset 7c464a9ecf48.

Please note that you'll probably need to export LANG=en_US.UTF-8 (or something like that, as most Linux distros do by default now), and you may need to install fonts that have non-English glyphs.

--ryan.

On 2014-08-10 13:27:06 +0000, Sik wrote:

Looks like this bug is back again?

What happens when I use all ASCII:
http://i.imgur.com/zU3qKiY.png

What happens when the value inside parenthesis is changed to "SÉGA MÉGA DRÍVE¡¡":
http://i.imgur.com/XNk3CHc.png

What happens when the value inside parenthesis is changed to "セガメガドライブ!!":
http://i.imgur.com/F37uR2q.png

SDL version 2.0.3-9008.

On 2015-02-19 05:22:19 +0000, Ryan C. Gordon wrote:

Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!

On 2015-03-10 18:05:24 +0000, Melker Narikka wrote:

I did some research on this a few months(?) ago, and the culprit is that XCreateFontSet() wants a UTF-8 locale to be set before being called.

It just so happens that when the application itself doesn't set the program-wide locale to something_or_other.UTF-8, things explode. A mere thread-specific uselocale() (and a locale restoration) in the message box functions didn't work in resolving the issue, so the fix might be a tad tricky to implement; a full-blown setlocale() was needed.

Hypothesis: this might maybe almost be fixable if from the very beginning we spawn an X thread that does all X communication, and set that thread's locale to something_or_other.UTF-8.

Just to recap: X wants you to set a UTF-8 locale yourself, and doesn't really let you do it in a thread-safe way.

On 2015-03-21 05:27:45 +0000, Ryan C. Gordon wrote:

Pretty sure this is the specific culprit:

https://hg.libsdl.org/SDL/rev/c259f0817583

--ryan.

On 2015-03-21 18:02:01 +0000, Ryan C. Gordon wrote:

(In reply to Ryan C. Gordon from comment # 7)

Pretty sure this is the specific culprit:

https://hg.libsdl.org/SDL/rev/c259f0817583

That is to say, if you flip SDL_SET_LOCALE to 1 in that file, the bug vanishes.

The downside is that setlocale() isn't thread safe, so while the message box is up, we can be screwing up other threads, and if one also set another locale while the message box is up, we'll reset it to the wrong value.

We already have code to fork() off and do the message box in a child process, so we can do whatever we want with setlocale(), but that got turned off too. I think it was considered too heavyweight? I don't know.

--ryan.

On 2015-03-23 23:56:28 +0000, Ryan C. Gordon wrote:

I turned this back on in https://hg.libsdl.org/SDL/rev/3df83030dab9, we'll see what happens.

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant