Fix: inconsistent allocation error handling

Mix-and-matching std::bad_alloc exception handling with nullptr checks
This commit is contained in:
Rubidium 2023-01-02 22:57:17 +01:00 committed by rubidium42
parent 3c54344825
commit fbd0f5ad7d
1 changed files with 2 additions and 6 deletions

View File

@ -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<MemBlock *>(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<MemBlock *>(new(std::nothrow) byte[_allocated_sprite_cache_size + _allocated_sprite_cache_size / 2]);
if (_spritecache_ptr != nullptr) {
/* Allocation succeeded, but we wanted less. */