From 81eb438482f176526e7d4e0de6d21be49580a27a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 16 Jul 2019 00:15:20 +0100 Subject: [PATCH] Fixes and tweaks --- src/Backends/Rendering/SDLTexture.cpp | 4 +++- src/Backends/Rendering/Software.cpp | 12 ++++++++++++ src/Draw.cpp | 8 ++++---- src/Main.cpp | 1 - 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 852fd519..ddc74248 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -86,6 +86,7 @@ BOOL Backend_Init(SDL_Window *window) void Backend_Deinit(void) { + SDL_DestroyTexture(screen_texture); SDL_DestroyRenderer(renderer); } @@ -126,9 +127,10 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) surface->needs_syncing = FALSE; surface->next = surface_list_head; + surface->prev = NULL; + surface_list_head = surface; if (surface->next) surface->next->prev = surface; - surface_list_head = surface; return surface; } diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 8ae95281..4978c018 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -130,6 +130,12 @@ void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Sur rect_clamped.bottom -= overflow; } + if (rect_clamped.bottom - rect_clamped.top <= 0) + return; + + if (rect_clamped.right - rect_clamped.left <= 0) + return; + // Do the actual blitting if (colour_key) { @@ -205,6 +211,12 @@ void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned cha rect_clamped.bottom -= overflow; } + if (rect_clamped.bottom - rect_clamped.top <= 0) + return; + + if (rect_clamped.right - rect_clamped.left <= 0) + return; + for (long j = 0; j < rect_clamped.bottom - rect_clamped.top; ++j) { unsigned char *source_pointer = &surface->pixels[((rect_clamped.top + j) * surface->pitch) + (rect_clamped.left * 3)]; diff --git a/src/Draw.cpp b/src/Draw.cpp index 3bf6c3da..283a97af 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -92,24 +92,24 @@ BOOL StartDirectDraw(int lMagnification, int lColourDepth) break; } + rgb24_pixel_format = SDL_AllocFormat(SDL_PIXELFORMAT_RGB24); + // Create renderer if (!Backend_Init(gWindow)) return FALSE; - rgb24_pixel_format = SDL_AllocFormat(SDL_PIXELFORMAT_RGB24); - return TRUE; } void EndDirectDraw() { - SDL_FreeFormat(rgb24_pixel_format); - // Release all surfaces for (int i = 0; i < SURFACE_ID_MAX; i++) ReleaseSurface(i); Backend_Deinit(); + + SDL_FreeFormat(rgb24_pixel_format); } static BOOL IsEnableBitmap(SDL_RWops *fp) diff --git a/src/Main.cpp b/src/Main.cpp index f3b98f7a..171eca8d 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -298,7 +298,6 @@ int main(int argc, char *argv[]) StartDirectDraw(2, colourDepth); - fullscreen = TRUE; SDL_ShowCursor(0); break; }