WinRT: fixed crash on ARM and x64 during OpenGL window init
authorDavid Ludwig <dludwig@pobox.com>
Thu, 26 Dec 2013 13:59:01 -0500
changeset 8572f8a89aa53309
parent 8571 f95a0f1bc631
child 8573 310a523cd32d
WinRT: fixed crash on ARM and x64 during OpenGL window init
src/video/winrt/SDL_winrtvideo.cpp
     1.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Thu Dec 26 11:04:35 2013 -0500
     1.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Thu Dec 26 13:59:01 2013 -0500
     1.3 @@ -266,8 +266,27 @@
     1.4          data->egl_surface = EGL_NO_SURFACE;
     1.5      } else {
     1.6          /* OpenGL ES 2 was reuqested.  Set up an EGL surface. */
     1.7 -        IUnknown * nativeWindow = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
     1.8 -        data->egl_surface = SDL_EGL_CreateSurface(_this, nativeWindow);
     1.9 +
    1.10 +        /* HACK: ANGLE/WinRT currently uses non-pointer, C++ objects to represent
    1.11 +           native windows.  The object only contains a single pointer to a COM
    1.12 +           interface pointer, which on x86 appears to be castable to the object
    1.13 +           without apparant problems.  On other platforms, notable ARM and x64,
    1.14 +           doing so will cause a crash.  To avoid this crash, we'll bypass
    1.15 +           SDL's normal call to eglCreateWindowSurface, which is invoked from C
    1.16 +           code, and call it here, where an appropriate C++ object may be
    1.17 +           passed in.
    1.18 +         */
    1.19 +        typedef EGLSurface (*eglCreateWindowSurfaceFunction)(EGLDisplay dpy, EGLConfig config,
    1.20 +            Microsoft::WRL::ComPtr<IUnknown> win,
    1.21 +            const EGLint *attrib_list);
    1.22 +        eglCreateWindowSurfaceFunction WINRT_eglCreateWindowSurface =
    1.23 +            (eglCreateWindowSurfaceFunction) _this->egl_data->eglCreateWindowSurface;
    1.24 +
    1.25 +        Microsoft::WRL::ComPtr<IUnknown> nativeWindow = reinterpret_cast<IUnknown *>(data->coreWindow.Get());
    1.26 +        data->egl_surface = WINRT_eglCreateWindowSurface(
    1.27 +            _this->egl_data->egl_display,
    1.28 +            _this->egl_data->egl_config,
    1.29 +            nativeWindow, NULL);
    1.30          if (data->egl_surface == NULL) {
    1.31              // TODO, WinRT: see if SDL_EGL_CreateSurface, or its callee(s), sets an error message.  If so, attach it to the SDL error.
    1.32              return SDL_SetError("SDL_EGL_CreateSurface failed");