Merge pull request #21188 from ZehMatt/fix-21171

Fix #21171: Crash creating entities with no slots available
This commit is contained in:
Matt 2024-01-13 01:17:50 +02:00 committed by GitHub
commit 35b19cade1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -4,6 +4,7 @@
- Improved: [#20951] Activate OpenRCT2 window after using native file dialog on macOS.
- Fix: [#21145] [Plugin] setInterval/setTimeout handle conflict.
- Fix: [#21158] [Plugin] Potential crash using setInterval/setTimeout within the callback.
- Fix: [#21171] [Plugin] Crash creating entities with no more entity slots available.
- Fix: [#21178] Inca Lost Citys scenario description incorrectly states there are height restrictions.
0.4.7 (2023-12-31)

View File

@ -341,11 +341,14 @@ EntityBase* CreateEntity(EntityType type)
if (EntityTypeIsMiscEntity(type))
{
// Misc sprites are commonly used for effects, if there are less than MAX_MISC_SPRITES
// free it will fail to keep slots for more relevant sprites.
// Also there can't be more than MAX_MISC_SPRITES sprites in this list.
uint16_t miscSlotsRemaining = MAX_MISC_SPRITES - GetMiscEntityCount();
if (miscSlotsRemaining >= _freeIdList.size())
// Misc sprites are commonly used for effects, give other entity types higher priority.
if (GetMiscEntityCount() >= MAX_MISC_SPRITES)
{
return nullptr;
}
// If there are less than MAX_MISC_SPRITES free slots, ensure other entities can be created.
if (_freeIdList.size() < MAX_MISC_SPRITES)
{
return nullptr;
}

View File

@ -233,6 +233,11 @@ namespace OpenRCT2::Scripting
DukValue createEntityType(duk_context* ctx, const DukValue& initializer)
{
TEntityType* entity = CreateEntity<TEntityType>();
if (entity == nullptr)
{
// Probably no more space for entities for this specified entity type.
return ToDuk(ctx, undefined);
}
auto entityPos = CoordsXYZ{ AsOrDefault(initializer["x"], 0), AsOrDefault(initializer["y"], 0),
AsOrDefault(initializer["z"], 0) };