# IMG\_Load requiring UTF8 for special characters

**URL:** <https://discourse.libsdl.org/t/img-load-requiring-utf8-for-special-characters/20845>\
**Category:** SDL Development\
**Created:** [July 17, 2014, 9:23am UTC](https://discourse.libsdl.org/t/img-load-requiring-utf8-for-special-characters/20845 "2014-07-17T09:23:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ande](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Ande](https://discourse.libsdl.org/u/Ande)\
**Post date:** [July 17, 2014, 9:23am UTC](https://discourse.libsdl.org/t/img-load-requiring-utf8-for-special-characters/20845/1 "2014-07-17T09:23:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rainer\_Deyke](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/a9a28c/32.png) [@Rainer\_Deyke](https://discourse.libsdl.org/u/Rainer_Deyke)\
**Post date:** [August 14, 2014, 7:57am UTC](https://discourse.libsdl.org/t/img-load-requiring-utf8-for-special-characters/20845/2 "2014-08-14T07:57:23Z")

</div>

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](http://eldwood.com))

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [August 15, 2014, 4:03am UTC](https://discourse.libsdl.org/t/img-load-requiring-utf8-for-special-characters/20845/3 "2014-08-15T04:03:58Z")

</div>

> > 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.
