|
1. Copying struct raises exception
|
|
Tue Feb 1, 2005 [5:57 AM]
|
mud_imp
mud_imp::AT::hotmail.com
member since: Jan 20, 2005
|
Reply
|
|
Original codebase: ROM I have successfully replaced old-style spec_fun in MOB_INDEX_DATA and CHAR_DATA with an array of mprogs:
SPEC_FUN * spec_fun[MAX_SPEC_PER_MOB]
Now I want to take the next step and replace it with the array of a structures representing mprog and its paramenters. To do that, I've defined the struct:
struct spec_data { SPEC_FUN * spec_fun; int args[MAX_SPEC_ARGS]; };
Now I am adding
SPEC_DATA * specs[MAX_SPEC_PER_MOB]
to the MOB_INDEX_DATA and CHAR_DATA. I've modified and added required procs so that memory is allocated for the new struct when creating a mobile, etc. It will compile and run fine. However, when I start adding the code that accesses or modifies any fields in that structure, such as:
if (ch->specs[i]->spec_fun == NULL)
the executable will crash. Obviously I am missing something related to proper memory management. Could you give me an advice?
|
|
|
|
|
2. RE: Copying struct raises exception
|
|
Tue Feb 1, 2005 [8:42 AM]
|
Lodren
Email not supplied
member since: Feb 18, 2004
|
In Reply To
Reply
|
|
It's hard to say without seeing more code. Best guess is that ch->specs[i] is NULL and you don't have a check for that in your code, or ch->specs[i] is uninitialized.
|
|
|
|
|