# sdl12-compat: video: Fix apps that UpdateRect and never PumpEvents.

**URL:** <https://discourse.libsdl.org/t/sdl12-compat-video-fix-apps-that-updaterect-and-never-pumpevents/39444>\
**Category:** SDL Commits\
**Created:** [October 21, 2022, 3:54am UTC](https://discourse.libsdl.org/t/sdl12-compat-video-fix-apps-that-updaterect-and-never-pumpevents/39444 "2022-10-21T03:54:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [October 21, 2022, 3:54am UTC](https://discourse.libsdl.org/t/sdl12-compat-video-fix-apps-that-updaterect-and-never-pumpevents/39444/1 "2022-10-21T03:54:02Z")

</div>

> <https://github.com/libsdl-org/sdl12-compat/commit/0668c11486d33eea06beae8782777001dd17459d>
>
> An app that \_only\_ calls SDL\_UpdateRects (perhaps to draw just a piece of
> animat…ion that doesn't cover the screen but while not accepting user input)
> will now check inside SDL\_UpdateRects itself to decide if enough time has
> gone by to warrant a present.
> 
> Also, if SDL\_Delay is called and a present is pending at all, just do it,
> as a signal from the app that the frame is complete. This catches things
> that update a rectangle and then delay for the user to view it.
> 
> Fixes #253.

```diff
From 0668c11486d33eea06beae8782777001dd17459d Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 20 Oct 2022 23:48:27 -0400
Subject: [PATCH] video: Fix apps that UpdateRect and never PumpEvents.

An app that _only_ calls SDL_UpdateRects (perhaps to draw just a piece of
animation that doesn't cover the screen but while not accepting user input)
will now check inside SDL_UpdateRects itself to decide if enough time has
gone by to warrant a present.

Also, if SDL_Delay is called and a present is pending at all, just do it,
as a signal from the app that the frame is complete. This catches things
that update a rectangle and then delay for the user to view it.

Fixes #253.
---
 src/SDL12_compat.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 4173b13dc..26b5caaef 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -6821,7 +6821,11 @@ SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL12_Rect *rects12)
         } else if (whole_screen) {
             PresentScreen(); /* flip it now. */
         } else {
- VideoSurfacePresentTicks = VideoSurfaceLastPresentTicks + GetDesiredMillisecondsPerFrame(); /* flip it later. */
+ if (!VideoSurfacePresentTicks) {
+ VideoSurfacePresentTicks = VideoSurfaceLastPresentTicks + GetDesiredMillisecondsPerFrame(); /* flip it later. */
+ } else if (SDL_TICKS_PASSED(SDL20_GetTicks(), VideoSurfacePresentTicks)) {
+ PresentScreen();
+ }
         }
 
         if (renderer) {
@@ -7828,9 +7832,14 @@ SDL_Delay(Uint32 ticks)
 {
     /* In case there's a loading screen from a background thread and the main thread is waiting... */
     const SDL_bool ThisIsSetVideoModeThread = (SDL20_ThreadID() == SetVideoModeThread) ? SDL_TRUE : SDL_FALSE;
- if (ThisIsSetVideoModeThread && VideoSurfaceUpdatedInBackgroundThread) {
- SDL_Flip(VideoSurface12); /* this will update the texture and present. */
+ if (ThisIsSetVideoModeThread) {
+ if (VideoSurfaceUpdatedInBackgroundThread) {
+ SDL_Flip(VideoSurface12); /* this will update the texture and present. */
+ } else if (VideoSurfacePresentTicks) {
+ PresentScreen();
+ }
     }
+
     SDL20_Delay(ticks);
 }
 

```
