Fixed crash if render target textures are used while the device is lost
authorSam Lantinga <slouken@libsdl.org>
Mon, 10 Feb 2014 13:40:02 -0800
changeset 8208 e749005cfd72
parent 8207 f06add42160c
child 8209 56e9c709db7e
Fixed crash if render target textures are used while the device is lost
src/render/direct3d/SDL_render_d3d.c
--- a/src/render/direct3d/SDL_render_d3d.c	Mon Feb 10 10:02:51 2014 -0800
+++ b/src/render/direct3d/SDL_render_d3d.c	Mon Feb 10 13:40:02 2014 -0800
@@ -1029,6 +1029,11 @@
     }
 #endif
 
+    if (!data) {
+        SDL_SetError("Texture is not currently available");
+        return -1;
+    }
+
     if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
         return -1;
     }
@@ -1068,6 +1073,11 @@
     }
 #endif
 
+    if (!data) {
+        SDL_SetError("Texture is not currently available");
+        return -1;
+    }
+
     if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
         return -1;
     }
@@ -1089,6 +1099,11 @@
     D3DLOCKED_RECT locked;
     HRESULT result;
 
+    if (!data) {
+        SDL_SetError("Texture is not currently available");
+        return -1;
+    }
+
     if (data->yuv) {
         /* It's more efficient to upload directly... */
         if (!data->pixels) {
@@ -1124,6 +1139,10 @@
 {
     D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
 
+    if (!data) {
+        return;
+    }
+
     if (data->yuv) {
         const SDL_Rect *rect = &data->locked_rect;
         void *pixels =
@@ -1155,7 +1174,12 @@
         return 0;
     }
 
-    texturedata = (D3D_TextureData *) texture->driverdata;
+    texturedata = (D3D_TextureData *)texture->driverdata;
+    if (!texturedata) {
+        SDL_SetError("Texture is not currently available");
+        return -1;
+    }
+
     result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture, 0, &data->currentRenderTarget);
     if(FAILED(result)) {
         return D3D_SetError("GetSurfaceLevel()", result);
@@ -1531,7 +1555,7 @@
                const SDL_Rect * srcrect, const SDL_FRect * dstrect)
 {
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
-    D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
+    D3D_TextureData *texturedata;
     LPDIRECT3DPIXELSHADER9 shader = NULL;
     float minx, miny, maxx, maxy;
     float minu, maxu, minv, maxv;
@@ -1543,6 +1567,12 @@
         return -1;
     }
 
+    texturedata = (D3D_TextureData *)texture->driverdata;
+    if (!texturedata) {
+        SDL_SetError("Texture is not currently available");
+        return -1;
+    }
+
     minx = dstrect->x - 0.5f;
     miny = dstrect->y - 0.5f;
     maxx = dstrect->x + dstrect->w - 0.5f;
@@ -1643,7 +1673,7 @@
                const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
 {
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
-    D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
+    D3D_TextureData *texturedata;
     LPDIRECT3DPIXELSHADER9 shader = NULL;
     float minx, miny, maxx, maxy;
     float minu, maxu, minv, maxv;
@@ -1656,6 +1686,12 @@
         return -1;
     }
 
+    texturedata = (D3D_TextureData *)texture->driverdata;
+    if (!texturedata) {
+        SDL_SetError("Texture is not currently available");
+        return -1;
+    }
+
     centerx = center->x;
     centery = center->y;