add proper recipe clean up on class delete

This commit is contained in:
DrPerkyLegit 2026-04-24 04:03:14 -04:00
parent 4cacbee4aa
commit 9af38d7a9d
5 changed files with 24 additions and 1 deletions

View file

@ -41,7 +41,7 @@ public:
unsigned short usBitmaskMissingGridIngredients[XUSER_MAX_COUNT]; // each bit set means we don't have that grid ingredient
}
INGREDIENTS_REQUIRED;
~Recipy() {}
~Recipy() = default;
virtual bool matches(shared_ptr<CraftingContainer> craftSlots, Level *level) = 0;
virtual shared_ptr<ItemInstance> assemble(shared_ptr<CraftingContainer> craftSlots) = 0;
virtual int size() = 0;

View file

@ -23,6 +23,17 @@ ShapedRecipy::ShapedRecipy(int width, int height, ItemInstance **recipeItems, It
_keepTag = false;
}
ShapedRecipy::~ShapedRecipy()
{
for (int i = 0; i < width * height; i++) {
if (recipeItems[i] == nullptr) continue;
delete recipeItems[i];
}
delete[] recipeItems;
delete result;
}
const int ShapedRecipy::getGroup()
{
return group;

View file

@ -12,6 +12,7 @@ public:
public:
ShapedRecipy(int width, int height, ItemInstance **recipeItems, ItemInstance *result, int iGroup=Recipy::eGroupType_Decoration);
~ShapedRecipy();
virtual const ItemInstance *getResultItem();
virtual const int getGroup();

View file

@ -19,6 +19,16 @@ ShapelessRecipy::ShapelessRecipy(ItemInstance *result, vector<ItemInstance *> *i
{
}
ShapelessRecipy::~ShapelessRecipy()
{
for (auto ingredient : *ingredients) {
delete ingredient;
}
delete ingredients;
delete result;
}
const int ShapelessRecipy::getGroup()
{
return group;

View file

@ -9,6 +9,7 @@ private:
public:
ShapelessRecipy(ItemInstance *result, vector<ItemInstance *> *ingredients, _eGroupType egroup=Recipy::eGroupType_Decoration);
~ShapelessRecipy();
virtual const ItemInstance *getResultItem();
virtual const int getGroup();