Fixed bug 1722 - An attempt to release NULL Direct3d surface
authorSam Lantinga <slouken@libsdl.org>
Sun, 17 Feb 2013 23:30:47 -0800
changeset 6895 031a1fd143ec
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
--- a/src/render/direct3d/SDL_render_d3d.c	Sat Feb 16 11:43:59 2013 -0800
+++ b/src/render/direct3d/SDL_render_d3d.c	Sun Feb 17 23:30:47 2013 -0800
@@ -362,7 +362,10 @@
     HRESULT result;
 
     /* Release the default render target before reset */
-    IDirect3DSurface9_Release(data->defaultRenderTarget);
+    if (data->defaultRenderTarget) {
+        IDirect3DSurface9_Release(data->defaultRenderTarget);
+        data->defaultRenderTarget = NULL;
+    }
 
     result = IDirect3DDevice9_Reset(data->device, &data->pparams);
     if (FAILED(result)) {
@@ -1486,7 +1489,10 @@
 
     if (data) {
         // Release the render target
-        IDirect3DSurface9_Release(data->defaultRenderTarget);
+        if (data->defaultRenderTarget) {
+            IDirect3DSurface9_Release(data->defaultRenderTarget);
+            data->defaultRenderTarget = NULL;
+        }
         if (data->currentRenderTarget != NULL) {
             IDirect3DSurface9_Release(data->currentRenderTarget);
             data->currentRenderTarget = NULL;