Hi all, I have 2 quick questions, I have a pure C text game, very small, just 1 test area created so far. But already 50% of the time I get a heap corruption crash (Visual studio IDE). I see about 4 functions in the call stack, with the last function shown below. I appreciate this probably won't be enough for anyway to determine why it got corrupted, but I just want to rule out any glaringly obvious errors with the below malloc wrapper, and typical usage.
but display_inventory takes a struct param. Is this the best way to get a generic function pointer and will I have to live with the warning? The basic design idea is to have an area, which has an array of option_t pointers, the player enters a number corresponding to one of the options, and the appropriate 'action' is executed. E.g.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void parse_cmd(area_t *area, int cmd)
if (cmd == ESCAPE_CMD)
if (cmd < 1 || cmd > area->numOfOptions)
int option = cmd - 1;
int isLookAround = strcmp(area->options[option]->name, "Look Around");
if (isLookAround == 0)
&display_inventory already has type void (*)(struct inventory *) so converting it into that type doesn't do anything.
I meant inventory->func_ptr = (void (*)(void)) &display_inventory;
And then when you call it it needs to be converted back into the original type
(((void (*)(struct inventory *))(inventory->func_ptr))(&my_inventory);