Fixed crash if render target textures are used while the device is lost
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index cf8f3fe..47675c7 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -1029,6 +1029,11 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
}
#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 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
}
#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 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
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_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
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 @@ D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
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 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
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 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
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 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
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 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
return -1;
}
+ texturedata = (D3D_TextureData *)texture->driverdata;
+ if (!texturedata) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
centerx = center->x;
centery = center->y;