From d2bc834fa960fd35d69f9a2ee252bebbe78f93c0 Mon Sep 17 00:00:00 2001 From: shevernitskiy Date: Mon, 11 Sep 2023 07:35:27 +0300 Subject: [PATCH] fix exception on close, dummy surface refcount --- library/modules/Textures.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/modules/Textures.cpp b/library/modules/Textures.cpp index b03821907..016a2193e 100644 --- a/library/modules/Textures.cpp +++ b/library/modules/Textures.cpp @@ -58,6 +58,7 @@ static std::unordered_map> g_tileset_to_h static std::vector g_delayed_regs; static std::mutex g_adding_mutex; static std::atomic loading_state = false; +static SDL_Surface* dummy_surface = NULL; // Converts an arbitrary Surface to something like the display format // (32-bit RGBA), and converts magenta to transparency if convert_magenta is set @@ -173,6 +174,7 @@ TexposHandle Textures::loadTexture(SDL_Surface* surface, bool reserved) { if (texpos != -1) { insert_texture(surface, texpos); g_handle_to_reserved_texpos.emplace(handle, texpos); + dummy_surface->refcount--; return handle; } @@ -431,8 +433,9 @@ static void reserve_static_range() { return; } reserved_range.init(enabler->textures.init_texture_size); - auto dummy_surface = DFSDL_CreateRGBSurfaceWithFormat( - SDL_DONTFREE, 0, 0, 32, SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGBA32); + dummy_surface = + DFSDL_CreateRGBSurfaceWithFormat(0, 0, 0, 32, SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGBA32); + dummy_surface->refcount += ReservedRange::size; for (int32_t i = 0; i < ReservedRange::size; i++) { add_texture(dummy_surface); }