I have been following the
Structured Programming tutorial.
When I attempt to do a ptr_remove on the panel in my remove function I get an "invalid pointer freed" error.
It is strange because the reset SHOW before it works fine.
I have tried both
ptr_remove(inventory->panel);
ptr_remove( inventory->panel );
The second options work sometimes.
Code
#define INVENTORY_MAX_SLOT 16
BMAP* empty_slot = "empty_slot.png";
BMAP* bmap_inventory = "inventory.png";
typedef struct {
var alive;
PANEL* panel;
//Slots for storing items
var max_slot;
var used_slot;
ItemSlot* slot[INVENTORY_MAX_SLOT];
} Inventory;
void inventory_remove(Inventory* inventory)
Inventory* inventory_create()
{
//Allocate a new inventory
Inventory* inventory = (Inventory*)malloc(sizeof(Inventory));
//Setup default values
inventory->alive = 1;
inventory->max_slot = INVENTORY_MAX_SLOT;
inventory->used_slot = 0;
inventory->panel = pan_create("bmap = bmap_inventory; flags = SHOW;", 1);
return inventory;
}
{
reset(inventory->panel, SHOW);
ptr_remove( inventory->panel );
//Remove all slots
var i;
for(i = 0; i < inventory->max_slot; i++)
{
itemslot_remove(inventory->slot[i]);
}
free(inventory->slot);
free(inventory);
}