Fixed crashes handling D3D11/12 device lost in testsprite

You can test this using "dxcap -forcetdr"
This commit is contained in:
Sam Lantinga
2024-10-21 00:12:16 -07:00
parent e2254b1045
commit 315842cf71
3 changed files with 35 additions and 4 deletions

View File

@@ -21,6 +21,7 @@
#define MAX_SPEED 1
static SDLTest_CommonState *state;
static const char *icon = "icon.bmp";
static int num_sprites;
static SDL_Texture **sprites;
static bool cycle_color;
@@ -56,6 +57,9 @@ static int LoadSprite(const char *file)
for (i = 0; i < state->num_windows; ++i) {
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
if (sprites[i]) {
SDL_DestroyTexture(sprites[i]);
}
sprites[i] = LoadTexture(state->renderers[i], file, true, &w, &h);
sprite_w = (float)w;
sprite_h = (float)h;
@@ -390,7 +394,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
SDL_Rect safe_area;
int i;
Uint64 seed;
const char *icon = "icon.bmp";
/* Initialize parameters */
num_sprites = NUM_SPRITES;
@@ -553,6 +556,9 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
if (event->type == SDL_EVENT_RENDER_DEVICE_RESET) {
LoadSprite(icon);
}
return SDLTest_CommonEventMainCallbacks(state, event);
}