Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixed SDL applications being killed immediately after being backgroun…

…ded, because they were trying to draw while minimized.
  • Loading branch information
slouken committed Nov 8, 2011
1 parent 6cf3718 commit 1ca94c1fa3dd8dfff6b5eeed2ae8d9eded77efdc
@@ -111,6 +111,10 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
viewport.w = renderer->viewport.w;
viewport.h = renderer->viewport.h;
SDL_RenderSetViewport(renderer, &viewport);
} else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
renderer->minimized = SDL_TRUE;
} else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
renderer->minimized = SDL_FALSE;
}
}
}
@@ -189,6 +193,12 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
renderer->magic = &renderer_magic;
renderer->window = window;

if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
renderer->minimized = SDL_TRUE;
} else {
renderer->minimized = SDL_FALSE;
}

SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);

SDL_RenderSetViewport(renderer, NULL);
@@ -873,6 +883,10 @@ SDL_RenderClear(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, -1);

/* Don't draw while we're minimized */
if (renderer->minimized) {
return 0;
}
return renderer->RenderClear(renderer);
}

@@ -899,6 +913,10 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
if (count < 1) {
return 0;
}
/* Don't draw while we're minimized */
if (renderer->minimized) {
return 0;
}
return renderer->RenderDrawPoints(renderer, points, count);
}

@@ -927,6 +945,10 @@ SDL_RenderDrawLines(SDL_Renderer * renderer,
if (count < 2) {
return 0;
}
/* Don't draw while we're minimized */
if (renderer->minimized) {
return 0;
}
return renderer->RenderDrawLines(renderer, points, count);
}

@@ -976,6 +998,10 @@ SDL_RenderDrawRects(SDL_Renderer * renderer,
return 0;
}

/* Don't draw while we're minimized */
if (renderer->minimized) {
return 0;
}
for (i = 0; i < count; ++i) {
if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
return -1;
@@ -1015,6 +1041,10 @@ SDL_RenderFillRects(SDL_Renderer * renderer,
if (count < 1) {
return 0;
}
/* Don't draw while we're minimized */
if (renderer->minimized) {
return 0;
}
return renderer->RenderFillRects(renderer, rects, count);
}

@@ -1072,6 +1102,10 @@ SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
texture = texture->native;
}

/* Don't draw while we're minimized */
if (renderer->minimized) {
return 0;
}
return renderer->RenderCopy(renderer, texture, &real_srcrect,
&real_dstrect);
}
@@ -1121,6 +1155,10 @@ SDL_RenderPresent(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, );

/* Don't draw while we're minimized */
if (renderer->minimized) {
return;
}
renderer->RenderPresent(renderer);
}

@@ -99,6 +99,7 @@ struct SDL_Renderer

/* The window associated with the renderer */
SDL_Window *window;
SDL_bool minimized;

/* The drawable area within the window */
SDL_Rect viewport;
@@ -279,6 +279,11 @@ GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
/* Rebind the context to the window area and update matrices */
SDL_CurrentContext = NULL;
}

if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
/* According to Apple documentation, we need to finish drawing NOW! */
glFinish();
}
}

static __inline__ int
@@ -169,6 +169,11 @@ GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
/* Rebind the context to the window area */
SDL_CurrentContext = NULL;
}

if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
/* According to Apple documentation, we need to finish drawing NOW! */
glFinish();
}
}

static int

0 comments on commit 1ca94c1

Please sign in to comment.