From 21bb021641d8408d3c1acc91f2b87e547e59add8 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 1 Mar 2021 10:56:15 +0000 Subject: [PATCH] Clean up gpBufEnd initialization Initialization of `gpBufEnd` was done in a convoluted way that only happened to work. Cleans up initialization and moves it to dx.cpp. --- Source/init.cpp | 1 - SourceX/dx.cpp | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/init.cpp b/Source/init.cpp index b1ca3c5fb..9963434c6 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -181,7 +181,6 @@ void init_create_window() app_fatal("Unable to create main window"); dx_init(); gbActive = true; - gpBufEnd = (BYTE *)(BUFFER_WIDTH * (SCREEN_HEIGHT + SCREEN_Y)); SDL_DisableScreenSaver(); } diff --git a/SourceX/dx.cpp b/SourceX/dx.cpp index 54757a60e..ceb832251 100644 --- a/SourceX/dx.cpp +++ b/SourceX/dx.cpp @@ -44,6 +44,7 @@ static void dx_create_back_buffer() } gpBuffer = (BYTE *)pal_surface->pixels; + gpBufEnd = gpBuffer; #ifndef USE_SDL1 // In SDL2, `pal_surface` points to the global `palette`. @@ -93,7 +94,7 @@ static void lock_buf_priv() } gpBuffer = (BYTE *)pal_surface->pixels; - gpBufEnd += (uintptr_t)(BYTE *)pal_surface->pixels; + gpBufEnd = (BYTE *)pal_surface->pixels + pal_surface->pitch * pal_surface->h; sgdwLockCount++; } @@ -114,7 +115,7 @@ static void unlock_buf_priv() sgdwLockCount--; if (sgdwLockCount == 0) { - gpBufEnd -= (uintptr_t)gpBuffer; + gpBufEnd = gpBuffer; } sgMemCrit.Leave(); }