sdl2_frt/src
Sam Lantinga a329c7f1c9 Fixed bug 2139 - SDL_CreateWindow/WIN_GL_LoadLibrary fails due to external iconv not being able to convert path
J?nis R?cis

Brief history:

We recently ported a game from SDL 1.2 to SDL 2. While doing Windows testing, I soon discovered that the game exits without opening a window with my cross-compiled SDL2.dll, but works great with the SDL2.dll from the MinGW SDK on libsdl.org. It was as simple as swapping out the DLLs to make it work.

Running the game in Wine showed that the game actually does run, up until the call to SDL_CreateWindow, which fails and leads the game to print out an error:

Failure to create window (LoadLibrary("OPENGL32.DLL"): (null))

Which basically says that there was no error, but maybe that's a Wine quirk.

The error string originates in SDL_windowsopengl.c, in WIN_GL_LoadLibrary, which contains this piece of code:

    wpath = WIN_UTF8ToString(path);
    _this->gl_config.dll_handle = LoadLibrary(wpath);
    SDL_free(wpath);
    if (!_this->gl_config.dll_handle) {
        char message[1024];
        SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
                     path);
        return WIN_SetError(message);
    }

After some digging, I discovered the culprit: WIN_UTF8ToString returns NULL. Why? Because it calls iconv_open from an iconv.dll that does not support the UCS-2-INTERNAL encoding. Why does the official SDL2.dll work? Because it calls no external iconv functions at all.

It turns out that the Fedora MinGW infrastructure (from which I obtained the conventiently prebuilt iconv.dll) does not provide a DLL from libiconv, but instead provides a DLL from a minimal Windows library called win-iconv. Which knows a good bit, but doesn't know anything about UCS-2-INTERNAL:

http://code.google.com/p/win-iconv/source/browse/trunk/win_iconv.c#155

So there are two problems here:

1) The error message is clearly useless, because LoadLibrary is an innocent bystander. Instead wpath should probably checked for NULL, and a more appropriate error should be set. Ideally something that makes it clear than an external iconv is causing trouble.
2) SDL doomed itself at the ./configure step, by finding an existing iconv and happily using it without confirming support for the mandatory encodings required by SDL.

There are certainly a few easy ways out of the situation (although I didn't yet manage to figure out how to prevent ./configure from looking for external iconv), but this had me completely stomped for a good while, so I figured it's worth writing down if anything.

(Search also found this, which talks a little about using UTF-16LE instead of UCS-2-INTERNAL: https://bugzilla.libsdl.org/show_bug.cgi?id=2075)
2013-10-18 00:13:51 -07:00
..
atomic Fixed building using MinGW 2013-10-17 23:02:29 -07:00
audio Fixed 1598 - Mingwin build fails on src/audio/xaudio2/SDL_xaudio2.c 2013-10-17 23:15:27 -07:00
core Fixed bug 2139 - SDL_CreateWindow/WIN_GL_LoadLibrary fails due to external iconv not being able to convert path 2013-10-18 00:13:51 -07:00
cpuinfo Fixed building using MinGW 2013-10-17 23:02:29 -07:00
events SDL_TEXTINPUT support for EVDEV 2013-10-03 10:28:10 -03:00
file Fixed building using MinGW 2013-10-17 23:02:29 -07:00
filesystem Fixed bug 2121 - GCC throws error on SDL_FORCE_INLINE when compiling with -ansi 2013-09-30 22:35:32 -07:00
haptic Christoph Mallon: Remove pointless if (x) before SDL_free(x) 2013-08-29 08:29:21 -07:00
input/evdev Prevent keystrokes from leaking through to the console when using evdev. 2013-10-13 17:15:43 -03:00
joystick Fixed bug 2069 - Device addition/removal queries all USB devices rather than only HID devices. 2013-10-17 23:40:13 -07:00
libm OCD fixes: Adds a space after /* (glory to regular expressions!) 2013-08-21 09:47:10 -03:00
loadso Rolled back my LoadLibrary change. The first failed call causes a dialog to pop up in Windows apps (but not console apps) and that's really bad. I'll have to deal with this in my app. 2013-09-28 14:06:39 -07:00
main Fixed building using MinGW 2013-10-17 23:02:29 -07:00
power Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
render Fixed building using MinGW 2013-10-17 23:02:29 -07:00
stdlib Fixed building using MinGW 2013-10-17 23:02:29 -07:00
test Fixed building using MinGW 2013-10-17 23:02:29 -07:00
thread Fixed building using MinGW 2013-10-17 23:02:29 -07:00
timer Fixes bug #2074 - Thanks Sylvain! 2013-08-29 14:03:44 -03:00
video Removed redundant #ifdef 2013-10-17 23:05:40 -07:00
SDL_assert_c.h Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
SDL_assert.c Fixed building using MinGW 2013-10-17 23:02:29 -07:00
SDL_error_c.h Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
SDL_error.c Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
SDL_hints.c Christoph Mallon: Remove pointless if (x) before SDL_free(x) 2013-08-29 08:29:21 -07:00
SDL_log.c Fixed building using MinGW 2013-10-17 23:02:29 -07:00
SDL.c Fixed building using MinGW 2013-10-17 23:02:29 -07:00