Simple Directmedia Layer
Go to file
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
acinclude Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
android-project Fixed bug 2155 - automatically remap accelerometer coordinates according to screen orientation on Android 2013-10-17 23:44:30 -07:00
build-scripts Do a full sysroot for the Raspberry Pi buildbot. 2013-10-11 10:58:05 -04:00
cmake Separate EGL / GL ES detection in CMake 2013-08-22 14:56:07 -03:00
debian Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
include Added an API to get the amount of system RAM 2013-10-17 11:32:56 -07:00
src 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
test Fixed building using MinGW 2013-10-17 23:02:29 -07:00
VisualC Fixed project conflict during commit 2013-10-14 09:14:09 -07:00
Xcode Updated SDL to version 2.0.1 2013-10-10 21:50:25 -07:00
Xcode-iOS OCD fixes: Adds a space after /* (glory to regular expressions!) 2013-08-21 09:47:10 -03:00
.hgignore Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module. 2013-08-20 19:57:11 -04:00
Android.mk Fixed bug 2146 - Enable static linking of libSDL on Android 2013-10-10 21:51:39 -07:00
autogen.sh Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
BUGS.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
CMakeLists.txt Updated SDL to version 2.0.1 2013-10-10 21:50:25 -07:00
configure Fixed bug 2149 - Don't search for libusbhid except on BSD 2013-10-13 19:49:45 -07:00
configure.in Fixed bug 2149 - Don't search for libusbhid except on BSD 2013-10-13 19:49:45 -07:00
COPYING.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
CREDITS.txt Added Julian Winter to the credits for the SDL 2.0 website. 2013-08-12 08:45:37 -07:00
INSTALL.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
Makefile.in Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module. 2013-08-20 19:57:11 -04:00
Makefile.minimal Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module. 2013-08-20 19:57:11 -04:00
Makefile.pandora Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module. 2013-08-20 19:57:11 -04:00
Makefile.psp Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module. 2013-08-20 19:57:11 -04:00
Makefile.wiz Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-android.txt Fixed bug 2146 - Enable static linking of libSDL on Android 2013-10-10 21:51:39 -07:00
README-cmake.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-directfb.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-gesture.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-hg.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-ios.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-macosx.txt Mac: Better handling when someone else is the app delegate. 2013-10-07 16:01:40 -07:00
README-pandora.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-platforms.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-porting.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-psp.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-raspberrypi.txt Prevent keystrokes from leaking through to the console when using evdev. 2013-10-13 17:15:43 -03:00
README-SDL.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-touch.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README-wince.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
README.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
sdl2-config.in Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
sdl2.m4 Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
sdl2.pc.in Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
SDL2.spec.in Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
TODO.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
VisualC.html Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00
WhatsNew.txt Fixes #2022, do not resume on Android when surfaceChanged 2013-08-12 11:13:50 -03:00

                         Simple DirectMedia Layer

                                  (SDL)

                                Version 2.0

---
http://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed
to provide low level access to audio, keyboard, mouse, joystick, and graphics
hardware via OpenGL and Direct3D. It is used by video playback software,
emulators, and popular games including Valve's award winning catalog
and many Humble Bundle games.

SDL officially supports Windows, Mac OS X, Linux, iOS, and Android.
Support for other platforms may be found in the source code.

SDL is written in C, works natively with C++, and there are bindings 
available for several other languages, including C# and Python.

This library is distributed under the zlib license, which can be found
in the file "COPYING.txt".

The best way to learn how to use SDL is to check out the header files in
the "include" subdirectory and the programs in the "test" subdirectory.
The header files and test programs are well commented and always up to date.
More documentation and FAQs are available online at:
	http://wiki.libsdl.org/

If you need help with the library, or just want to discuss SDL related
issues, you can join the developers mailing list:
	http://www.libsdl.org/mailing-list.php

Enjoy!
	Sam Lantinga				(slouken@libsdl.org)