IMG_Load requiring UTF8 for special characters

I wanted to make small updates to my old game project and along with that, I decided to update SDL 1.2.13 to 1.2.15.

However, I noticed that image loading stopped working for file names with special characters (Windows 8, Visual Studio 2013). This is most probably because of this change in 1.2.14: “SDL_RWFromFile() takes a UTF-8 filename when opening a file”.

What I am doing is I am reading a directory with dirent compliant opendir + readdir which return ANSI strings I put to IMG_Load. With 1.2.13 this worked but not with 1.2.15 anymore. I can still open files with fopen using those strings but it doesn’t help much since SDL_RWFromFP is not supported by Windows. My current workaround is to load everything to a buffer and use IMG_Load_RW with a memory buffer but surely that is not the best solution here?

Is there some easy way to convert an ANSI string to UTF-8 so that I can be sure it works on all locales and all platforms the same way it did with 1.2.13? In my game, I have my own fixed 256 character font so I don’t care about code pages etc.

No, this never worked. You just got lucky. Just try putting a file
named ???.png in the directory and watch it crash and burn.On 17.07.2014 11:23, Ande wrote:

I wanted to make small updates to my old game project and along with
that, I decided to update SDL 1.2.13 to 1.2.15.

However, I noticed that image loading stopped working for file names
with special characters (Windows 8, Visual Studio 2013). This is most
probably because of this change in 1.2.14: “SDL_RWFromFile() takes a
UTF-8 filename when opening a file”.

What I am doing is I am reading a directory with dirent compliant
opendir + readdir which return ANSI strings I put to IMG_Load. With
1.2.13 this worked but not with 1.2.15 anymore.


Rainer Deyke (rainerd at eldwood.com)

What I am doing is I am reading a directory with dirent compliant
opendir + readdir which return ANSI strings I put to IMG_Load. With
1.2.13 this worked but not with 1.2.15 anymore.

No, this never worked. You just got lucky. Just try putting a file
named ???.png in the directory and watch it crash and burn.

To be more clear, you probably didn’t have an ASCII string, you probably
had a Latin1 string (that is, you probably had something that was
alphanumeric English characters and maybe something with an accent over
it?).

You can convert between this and UTF-8 with SDL_iconv()…just be
careful, those accented chars will probably grow from 1 byte to 2 bytes
(and if you get into some languages, they might be 4 bytes).

Alternately, Low ASCII (basically, unaccented English letters and
numbers and punctuation) happens to be valid UTF-8, so if you control
your file names, just rename them appropriately and your existing code
will work without drama.

–ryan.