D3D11: Fixed a crash after a GPU device-reset on Win32
authorDavid Ludwig <dludwig@pobox.com>
Sun, 23 Mar 2014 16:08:32 -0400
changeset 866962dfa45e5e08
parent 8668 07dce0097f29
child 8670 0c15c8a2f8c3
D3D11: Fixed a crash after a GPU device-reset on Win32
src/render/direct3d11/SDL_render_d3d11.c
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.c	Sun Mar 23 13:48:16 2014 -0400
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.c	Sun Mar 23 16:08:32 2014 -0400
     1.3 @@ -851,6 +851,12 @@
     1.4      D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
     1.5      SDL_Texture *texture = NULL;
     1.6  
     1.7 +    /* Release all textures */
     1.8 +    for (texture = renderer->textures; texture; texture = texture->next) {
     1.9 +        D3D11_DestroyTexture(renderer, texture);
    1.10 +    }
    1.11 +
    1.12 +    /* Release/reset everything else */
    1.13      if (data) {
    1.14          SAFE_RELEASE(data->dxgiFactory);
    1.15          SAFE_RELEASE(data->dxgiAdapter);
    1.16 @@ -874,13 +880,6 @@
    1.17          SAFE_RELEASE(data->clippedRasterizer);
    1.18          SAFE_RELEASE(data->vertexShaderConstants);
    1.19  
    1.20 -        if (data->hD3D11Mod) {
    1.21 -            SDL_UnloadObject(data->hD3D11Mod);
    1.22 -        }
    1.23 -        if (data->hDXGIMod) {
    1.24 -            SDL_UnloadObject(data->hDXGIMod);
    1.25 -        }
    1.26 -
    1.27          data->swapEffect = (DXGI_SWAP_EFFECT) 0;
    1.28          data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
    1.29          data->currentRenderTargetView = NULL;
    1.30 @@ -889,11 +888,18 @@
    1.31          data->currentShader = NULL;
    1.32          data->currentShaderResource = NULL;
    1.33          data->currentSampler = NULL;
    1.34 -    }
    1.35  
    1.36 -    /* Release all textures */
    1.37 -    for (texture = renderer->textures; texture; texture = texture->next) {
    1.38 -        D3D11_DestroyTexture(renderer, texture);
    1.39 +        /* Unload the D3D libraries.  This should be done last, in order
    1.40 +         * to prevent IUnknown::Release() calls from crashing.
    1.41 +         */
    1.42 +        if (data->hD3D11Mod) {
    1.43 +            SDL_UnloadObject(data->hD3D11Mod);
    1.44 +            data->hD3D11Mod = NULL;
    1.45 +        }
    1.46 +        if (data->hDXGIMod) {
    1.47 +            SDL_UnloadObject(data->hDXGIMod);
    1.48 +            data->hDXGIMod = NULL;
    1.49 +        }
    1.50      }
    1.51  }
    1.52