mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: inconsistent allocation error handling
Mix-and-matching std::bad_alloc exception handling with nullptr checks
This commit is contained in:
parent
3c54344825
commit
fbd0f5ad7d
|
@ -988,12 +988,8 @@ static void GfxInitSpriteCache()
|
||||||
_allocated_sprite_cache_size = target_size;
|
_allocated_sprite_cache_size = target_size;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
|
||||||
/* Try to allocate 50% more to make sure we do not allocate almost all available. */
|
/* 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]);
|
_spritecache_ptr = reinterpret_cast<MemBlock *>(new(std::nothrow) byte[_allocated_sprite_cache_size + _allocated_sprite_cache_size / 2]);
|
||||||
} catch (std::bad_alloc &) {
|
|
||||||
_spritecache_ptr = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_spritecache_ptr != nullptr) {
|
if (_spritecache_ptr != nullptr) {
|
||||||
/* Allocation succeeded, but we wanted less. */
|
/* Allocation succeeded, but we wanted less. */
|
||||||
|
|
Loading…
Reference in New Issue