Fixed bug 1722 - An attempt to release NULL Direct3d surface
authorSam Lantinga <slouken@libsdl.org>
Sun, 17 Feb 2013 23:30:47 -0800
changeset 6895031a1fd143ec
parent 6894 5b5329b1576f
child 6896 d2c17a7761cb
Fixed bug 1722 - An attempt to release NULL Direct3d surface

Evgeny

static void
D3D_DestroyRenderer(SDL_Renderer * renderer)

has a critical problem. It may try to release IDirect3DSurface9 surface pointed
by NULL pointer. That leads to really wierd consequences on my system.

It happens when the previous call to IDirect3D9_CreateDevice() fails leaving
D3D_RenderData::defaultRenderTarget uninitialized.
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sat Feb 16 11:43:59 2013 -0800
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Sun Feb 17 23:30:47 2013 -0800
     1.3 @@ -362,7 +362,10 @@
     1.4      HRESULT result;
     1.5  
     1.6      /* Release the default render target before reset */
     1.7 -    IDirect3DSurface9_Release(data->defaultRenderTarget);
     1.8 +    if (data->defaultRenderTarget) {
     1.9 +        IDirect3DSurface9_Release(data->defaultRenderTarget);
    1.10 +        data->defaultRenderTarget = NULL;
    1.11 +    }
    1.12  
    1.13      result = IDirect3DDevice9_Reset(data->device, &data->pparams);
    1.14      if (FAILED(result)) {
    1.15 @@ -1486,7 +1489,10 @@
    1.16  
    1.17      if (data) {
    1.18          // Release the render target
    1.19 -        IDirect3DSurface9_Release(data->defaultRenderTarget);
    1.20 +        if (data->defaultRenderTarget) {
    1.21 +            IDirect3DSurface9_Release(data->defaultRenderTarget);
    1.22 +            data->defaultRenderTarget = NULL;
    1.23 +        }
    1.24          if (data->currentRenderTarget != NULL) {
    1.25              IDirect3DSurface9_Release(data->currentRenderTarget);
    1.26              data->currentRenderTarget = NULL;