sdl12-compat: video: SDL_UpdateRects must own the renderer to touch the screen texture.

From 4fc061cd35ec12b296b96a160923e08fa2c2d0b4 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 4 Oct 2022 15:01:52 -0400
Subject: [PATCH] video: SDL_UpdateRects must own the renderer to touch the
 screen texture.

Fixes #230.
---
 src/SDL12_compat.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index a40e7e1a8..3c69b953e 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -6656,15 +6656,20 @@ SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL12_Rect *rects12)
         const int pixsize = surface12->format->BytesPerPixel;
         const int srcpitch = surface12->pitch;
         SDL_bool whole_screen = SDL_FALSE;
+        SDL_Renderer *renderer = NULL;
         void *pixels = NULL;
         SDL_Rect rect20;
         int pitch = 0;
         int i, j;
 
+        if (!upload_later) {
+            renderer = LockVideoRenderer();  /* must own the renderer before locking the texture! */
+        }
+
         for (i = 0; i < numrects; i++) {
             UpdateRect12to20(surface12, &rects12[i], &rect20, &whole_screen);
 
-            if (upload_later) {
+            if (!renderer) {
                 continue;
             } else if (!rect20.w || !rect20.h) {
                 continue;
@@ -6711,6 +6716,10 @@ SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL12_Rect *rects12)
         } else {
             VideoSurfacePresentTicks = VideoSurfaceLastPresentTicks + GetDesiredMillisecondsPerFrame();  /* flip it later. */
         }
+
+        if (renderer) {
+            UnlockVideoRenderer();
+        }
     }
 }