1
0

Fix comparator segfaults

The handler would get called for any BlockEntity, but not every BlockEntity is a BlockEntityWithItems. Downcasting with static_cast is UB on fail.
This commit is contained in:
Marvin Kopf 2016-12-06 10:40:34 +01:00
parent 7e8f66cf94
commit d394042694

View File

@ -54,7 +54,14 @@ public:
virtual bool Item(cBlockEntity * a_BlockEntity) override
{
auto & Contents = static_cast<cBlockEntityWithItems *>(a_BlockEntity)->GetContents();
// Skip BlockEntities that don't have slots
auto BlockEntityWithItems = dynamic_cast<cBlockEntityWithItems *>(a_BlockEntity);
if (BlockEntityWithItems == nullptr)
{
return false;
}
auto & Contents = BlockEntityWithItems->GetContents();
float Fullness = 0; // Is a floating-point type to allow later calculation to produce a non-truncated value
for (int Slot = 0; Slot != Contents.GetNumSlots(); ++Slot)