From fbd0f5ad7d75eb8bb5e2402ce8119a0a86e606db Mon Sep 17 00:00:00 2001 From: Rubidium Date: Mon, 2 Jan 2023 22:57:17 +0100 Subject: [PATCH] Fix: inconsistent allocation error handling Mix-and-matching std::bad_alloc exception handling with nullptr checks --- src/spritecache.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 2b3ba095c1..08b1ad85a9 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -988,12 +988,8 @@ static void GfxInitSpriteCache() _allocated_sprite_cache_size = target_size; do { - try { - /* Try to allocate 50% more to make sure we do not allocate almost all available. */ - _spritecache_ptr = reinterpret_cast(new byte[_allocated_sprite_cache_size + _allocated_sprite_cache_size / 2]); - } catch (std::bad_alloc &) { - _spritecache_ptr = nullptr; - } + /* Try to allocate 50% more to make sure we do not allocate almost all available. */ + _spritecache_ptr = reinterpret_cast(new(std::nothrow) byte[_allocated_sprite_cache_size + _allocated_sprite_cache_size / 2]); if (_spritecache_ptr != nullptr) { /* Allocation succeeded, but we wanted less. */