Fixed a crash on Windows Phone 8 that occurred after rotating a device

This changeset prevents IDXGISwapChain::ResizeBuffers from being invoked on
Windows Phone 8, a function that isn't available on the platform (but is
available on other Windows platforms).  The call would fail, which ultimately
led to a crash.

This changeset also attempts to make sure that the D3D11 swap chain is created
at the correct size, when using Windows Phone 8.

Still TODO: make sure rotation-querying works across relevant Windows
platforms (that support Direct3D 11.x).
This commit is contained in:
David Ludwig 2014-03-15 13:27:18 -04:00
parent 205266fa03
commit 5281f9f1ea

View file

@ -1438,30 +1438,24 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
ID3D11Texture2D *backBuffer = NULL; ID3D11Texture2D *backBuffer = NULL;
HRESULT result = S_OK; HRESULT result = S_OK;
int w, h; int w, h;
BOOL swapDimensions;
/* Release the previous render target view */ /* Release the previous render target view */
D3D11_ReleaseMainRenderTargetView(renderer); D3D11_ReleaseMainRenderTargetView(renderer);
/* The width and height of the swap chain must be based on the window's /* The width and height of the swap chain must be based on the display's
* landscape-oriented width and height. If the window is in a portrait * non-rotated size.
* rotation, the dimensions must be reversed.
*/ */
SDL_GetWindowSize(renderer->window, &w, &h); SDL_GetWindowSize(renderer->window, &w, &h);
data->rotation = D3D11_GetCurrentRotation(); data->rotation = D3D11_GetCurrentRotation();
if (D3D11_IsDisplayRotated90Degrees(data->rotation)) {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
swapDimensions = FALSE;
#else
swapDimensions = D3D11_IsDisplayRotated90Degrees(data->rotation);
#endif
if (swapDimensions) {
int tmp = w; int tmp = w;
w = h; w = h;
h = tmp; h = tmp;
} }
if (data->swapChain) { if (data->swapChain) {
/* IDXGISwapChain::ResizeBuffers is not available on Windows Phone 8. */
#if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
/* If the swap chain already exists, resize it. */ /* If the swap chain already exists, resize it. */
result = IDXGISwapChain_ResizeBuffers(data->swapChain, result = IDXGISwapChain_ResizeBuffers(data->swapChain,
0, 0,
@ -1473,6 +1467,7 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain::ResizeBuffers", result); WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGISwapChain::ResizeBuffers", result);
goto done; goto done;
} }
#endif
} else { } else {
result = D3D11_CreateSwapChain(renderer, w, h); result = D3D11_CreateSwapChain(renderer, w, h);
if (FAILED(result)) { if (FAILED(result)) {