sdl12-compat: Handle SDL_WM_GrabInput() when VideoSurface12 is NULL

From ebcbb11caf34f5ee99377a8da4c98f9770c694b8 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Wed, 19 May 2021 17:55:43 +0800
Subject: [PATCH] Handle SDL_WM_GrabInput() when VideoSurface12 is NULL
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It's possible for HandleInputGrab() — which is called by
SDL_WM_GrabInput() — to dereference a NULL pointer when attempting to
check if the window is fullscreen. Assume that, if VideoSurface12 is
NULL, we don't have a fullscreen window, and so shouldn't automatically
grab.

This was causing Psychonauts to crash on startup, as it called
SDL_WM_GrabInput() before SDL_SetVideoMode().
---
 src/SDL12_compat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 25b670d..15c5c7e 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -4124,7 +4124,8 @@ static void
 HandleInputGrab(SDL12_GrabMode mode)
 {
     /* SDL 1.2 always grabbed input if the video mode was fullscreen. */
-    const SDL_bool wantgrab = ((VideoSurface12->flags & SDL12_FULLSCREEN) || (mode == SDL12_GRAB_ON)) ? SDL_TRUE : SDL_FALSE;
+    const SDL_bool isfullscreen = (VideoSurface12 && (VideoSurface12->flags & SDL12_FULLSCREEN)) ? SDL_TRUE : SDL_FALSE;
+    const SDL_bool wantgrab = (isfullscreen || (mode == SDL12_GRAB_ON)) ? SDL_TRUE : SDL_FALSE;
     if (VideoWindowGrabbed != wantgrab) {
         SDL20_SetWindowGrab(VideoWindow20, wantgrab);
         VideoWindowGrabbed = wantgrab;