Reset the viewport when we reset the other D3D state.
authorSam Lantinga
Wed, 07 Aug 2013 01:14:04 -0700
changeset 75866f1539dc6b57
parent 7585 7fd59fc01ee7
child 7587 6438df1610ae
Reset the viewport when we reset the other D3D state.

From Sythical:

Hello, I've created a simple SDL2 application which draws a texture on the screen. The problem I'm having is that if I launch another program which loads the UAC popup or if I lock my PC and then login again, the application stops drawing the texture. I tried adding SDL_Delay(10000) after SDL_RenderPresent(renderer). This made the texture stay on the screen for a little bit but the texture wasn't drawn again after the delay. Here's my code:

#include "SDL.h"

int main(int argc, char *argv[])
{
SDL_Renderer *renderer;
SDL_Window *window;
SDL_Surface *surface;
SDL_Texture *rect_texture;
SDL_Event main_event;
SDL_Rect rect_data;
int enable_vsync = 1;

if(SDL_Init(SDL_INIT_VIDEO) < 0) return 1;

window = SDL_CreateWindow("SDL2 Application", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_RESIZABLE);

renderer = SDL_CreateRenderer(window, -1, enable_vsync ? SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC : SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 20, 20, 30, 255);

surface = SDL_LoadBMP("icon.bmp");
rect_texture = SDL_CreateTextureFromSurface(renderer, surface);

rect_data.w = 32; rect_data.h = 32;
rect_data.x = 300; rect_data.y = 300;

while(main_event.type != SDL_QUIT)
{
SDL_PollEvent(&main_event);

SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, rect_texture, NULL, &rect_data);
SDL_RenderPresent(renderer);
}

SDL_DestroyTexture(rect_texture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();

return 0;
}
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Wed Aug 07 00:46:42 2013 -0700
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Wed Aug 07 01:14:04 2013 -0700
     1.3 @@ -424,6 +424,7 @@
     1.4      IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
     1.5      IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
     1.6      SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
     1.7 +    D3D_UpdateViewport(renderer);
     1.8      return 0;
     1.9  }
    1.10  
    1.11 @@ -449,7 +450,6 @@
    1.12          if (D3D_Reset(renderer) < 0) {
    1.13              return -1;
    1.14          }
    1.15 -        D3D_UpdateViewport(renderer);
    1.16  
    1.17          data->updateSize = SDL_FALSE;
    1.18      }