mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #21188 from ZehMatt/fix-21171
Fix #21171: Crash creating entities with no slots available
This commit is contained in:
commit
35b19cade1
|
@ -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 City’s scenario description incorrectly states there are height restrictions.
|
||||
|
||||
0.4.7 (2023-12-31)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) };
|
||||
|
|
Loading…
Reference in New Issue